Welcome

Welcome, thanks to look my blog

Friday, 9 January 2015

combo bertingkat

index.php
<html>
<head><title>Select Chain</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
var htmlobjek;
$(document).ready(function(){
  //apabila terjadi event onchange terhadap object <select id=propinsi>
  $("#propinsi").change(function(){
    var propinsi = $("#propinsi").val();
    $.ajax({
        url: "ambilkota.php",
        data: "propinsi="+propinsi,
        cache: false,
        success: function(msg){
            //jika data sukses diambil dari server kita tampilkan
            //di <select id=kota>
            $("#kota").html(msg);
        }
    });
  });
  $("#kota").change(function(){
    var kota = $("#kota").val();
    $.ajax({
        url: "ambilkecamatan.php",
        data: "kota="+kota,
        cache: false,
        success: function(msg){
            $("#kec").html(msg);
        }
    });
  });
});

</script>
</head>
<body>
<?php
mysql_connect("localhost","root","z3les");
mysql_select_db("kp_spp2");
?>
Pilih Provinsi :<br>
<select name="propinsi" id="propinsi">
<option>--Pilih Provinsi--</option>
<?php
//mengambil nama-nama propinsi yang ada di database
$propinsi = mysql_query("SELECT * FROM master_tingkat_kelas ORDER BY id_tingkat_kelas");
while($p=mysql_fetch_array($propinsi)){
echo "<option value=\"$p[id_tingkat_kelas]\">$p[kelas]</option>\n";
}
?>
</select>
<br>Pilih Kabupaten/Kota :<br>
<select name="kota" id="kota">
<option>--Pilih Kabupaten/Kota--</option>
<?php
//mengambil nama-nama propinsi yang ada di database
$kota = mysql_query("SELECT * FROM master_siswa ORDER BY id_siswa");
while($p=mysql_fetch_array($propinsi)){
echo "<option value=\"$p[kelas]\">$p[nama_siswa]</option>\n";
}
?>
</select>

<br>Pilih Kecamatan :<br>
<select name="kec" id="kec">
<option>--Pilih Kecamatan--</option>
<?php
//mengambil nama-nama propinsi yang ada di database
$kec = mysql_query("SELECT * FROM tabel_biaya ORDER BY id_biaya");
while($p=mysql_fetch_array($kota)){
echo "<option value=\"$p[id_tingkat_kelas]\">$p[nama_biaya]</option>\n";
}
?>

</select>
</body>
</html>




ambilkota.php
<?php
mysql_connect("localhost","root","z3les");
mysql_select_db("kp_spp2");
$propinsi = $_GET['propinsi'];
$kota = mysql_query("SELECT * FROM tabel_biaya WHERE id_tingkat_kelas='$propinsi' order by id_biaya");
echo "<option>-- Pilih Kabupaten/Kota --</option>";
while($k = mysql_fetch_array($kota)){
     echo "<option value=\"".$k['id_tingkat_kelas']."\">".$k['nama_biaya']."</option>\n";
}
?>



ambilkecamatan.php
<?php
mysql_connect("localhost","root","z3les");
mysql_select_db("kp_spp2");
$kota = $_GET['kota'];
$kec = mysql_query("SELECT * FROM master_siswa WHERE kelas='$kota' order by id_siswa");
echo "<option>-- Pilih Kecamatan --</option>";
while($k = mysql_fetch_array($kec)){
    echo "<option value=\"".$k['kelas']."\">".$k['nama_siswa']."</option>\n";
}
?>

No comments:

Post a Comment