I tried to make a simple dependent drop down list and here is the table
php code for drop down list level 1:
<select name="level1" class="level1" onChange="get_level2(this.value)">
<option selected="selected">--level 1--</option>
= "SELECT * FROM table WHERE pid=0"= mysql_query($sql_level1);
= mysql_fetch_array($result_level1))
='".$row_level1['".$row_level1['kategori']."</option>";
}
?>
</select>
The level 1 drop down work fine, but I down know how to parsing the chosen id in level 1 to make drop down level 2 based on the pid value..
How to make the level 1 selected id become level 2 pid when level 1 onChange in javascript??
Still googling but still don't solved my problem...
if i try to parsing the id to another file like this, is it correct??
function get_level2(id)
{
$.ajax({
type: "POST",
url: "../include/level2.php", /* The fruit or animal id will be sent to this file */
beforeSend: function () {
$("#level2").html("<option>Loading ...</option>");
},
data: "level2_id="+id,
success: function(msg){
$("#level2").html(msg);
}
});
}
and this is the level2.php file:
<?php
include "../include/sqlConnect.php";
$level2_id = $_REQUEST['level2_id'];
$sql_level2 = "SELECT * FROM table WHERE pid = '".$level2_id."'";
$result_level2 = mysql_query($sql_level2);
echo "<select name='level2'>";
while($row_level2 = mysql_fetch_array($result_level2))
{
echo "<option value='".$row_level2['id']."'>".$row_level2['kategori']."</option>";
}
echo "</select>";
?>
Can anyone help me please..