I have got it working up to the third select list. But there are 4.
country, source, target and subject.
I am able to select up to the target select list alright, but I can’t make it to the final one, the subject. This is because I don’t know how to complete the missing code for that one.
Here is the script and further below will be the processing one. So it is the ‘subject’ select list that needs to move accordingly to its next to the left:
jQuery(document).ready(function () {
jQuery("#sel_pais").change(function () {
//
var datatosend = 'pais_id=' + jQuery(this).val();
jQuery.ajax({
type:'GET',
url:'includes/getchilds2.php',
data:datatosend,
dataType:"json",
success:function (data) {
jQuery('#sel_source').find('option').remove().end();
jQuery('#sel_target').find('option').remove().end();
jQuery.each(data, function (index, val) {
var newopt = '<option value="' + val.key + '">' + val.title + '</option>';
jQuery('#sel_source').append(newopt);
});
jQuery('#sel_target').append('<option value="-1">Select</option>');
}
});
});
//////////////////////
jQuery("#sel_source").change(function () {
//
var datatosend = 'id_from=' + jQuery(this).val();
jQuery.ajax({
type:'GET',
url:'includes/getchilds2.php',
data:datatosend,
dataType:"json",
success:function (data) {
jQuery('#sel_target').find('option').remove().end();
jQuery.each(data, function (index, val) {
var newopt = '<option value="' + val.key + '">' + val.title + '</option>';
jQuery('#sel_target').append(newopt);
});
}
});
});
});
And here is the processing one:
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("traducteurs", $con);
//
if (isset($_GET['pais_id'])) {
$curid = $_GET['pais_id'];
//
$result = mysql_query("SELECT * FROM tabla_from where pais_id=" . $curid);
if (mysql_num_rows($result) > 0) {
$op = '[';
$op .= '{"title":"Select","key":"-1"},';
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$op .= '{';
$op .= '"title":"' . $row['from_name'] . '", "key":"' . $row['id_from'] . '"';
$op .= '},';
}
$op = substr($op, 0, -1);
$op .= ']';
echo $op;
}
else {
echo '[{"title":"Select","key":"-1"}]';
}
}
/////////////////////
if (isset($_GET['id_from'])) {
$curid = $_GET['id_from'];
//
$result = mysql_query("SELECT * FROM tabla_into where id_from=" . $curid);
if (mysql_num_rows($result) > 0) {
$op = '[';
$op .= '{"title":"Select","key":"-1"},';
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$op .= '{';
$op .= '"title":"' . $row['into_language'] . '", "key":"' . $row['id_into'] . '"';
$op .= '},';
}
$op = substr($op, 0, -1);
$op .= ']';
echo $op;
}
else {
echo '[{"title":"Select","key":"-1"}]';
}
}
?>
I am using this code to show interdependent list
php sample code you can change.. repeat the below code for others.
hope this will help you.