[trick] Pergantian Form Onchange Javascript

Code Html


<html>
<head>
<title>Pergantian Form Onchange</title>
<script>
function ganti(){
var a = document.getElementById("pilihan").value;
if(a == ""){
document.getElementById("status").innerHTML="Pilih Dulu Ya";
}else{
var ajak =new XMLHttpRequest();
var url = "combo.php";
var nilai = "variable="+a;
ajak.open("POST",url,true);
ajak.setRequestHeader("Content-type","application/x-www-form-urlencoded");
ajak.onreadystatechange = function(){
if(ajak.readyState == 4 && ajak.status == 200){
var return_data = ajak.responseText;
document.getElementById("status").innerHTML= return_data;
}
}
ajak.send(nilai);
document.getElementById("status").innerHTML="Prosessss";
}
}
</script>
</head>

<body>
<form method=POST action="tujuan.php">
Pilih Variable : <select id="pilihan" onchange="ganti()">
<option value="00">Pilih Variable </option>
<option value="01">01</option>
<option value="02">02</option>
</select>
<div id="status">
<p>UN : <input type=text name='username'></p>
<p>LN : <input type=text name='lastname'></p>
</div>
<input type="submit" value="simpan">
</form>
</body>
</html>

Code Php


<?php
if($_POST['variable']==01){
echo"<p>UN : <input type=text name='username' value='01'></p>";
echo"<p>LN : <input type=text name='lastname' value='02'></p>";
}else{
echo"<p>UN : <input type=text name='username' value='03'></p>";
echo"<p>LN : <input type=text name='lastname' value='04'></p>";
}
?>

Leave a comment

1 Comment

  1. Reblogged this on Dinesh Ram Kali..

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: