Hello,
I found a cascading dropdown list script and its works but im not sure how to pull in the user selection to evaluate in PHP.
I think i need a way to pass the javascript variable to php but not sure how…can someone look at the code below and let me know
not sure if you guys would appreciate me postng someone elses url so ill copy and past the code.
file1.php
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
select
<div style="padding-left:30px; height:710px;">
<br clear="all" /><br clear="all" />
<div id="show_sub_categories">
<select name="search_category" class="parent">
<option value="" selected="selected">-- Categories --</option>
<?php
foreach($catList->catArrayResults() AS $key1 => $value1)
{ if($value1['node_parent'] == 0)
{ echo '<option value="' . $value1['node_inx'] . '">' . $value1['node_name'] . '</option>'; }
}
?>
</select>
</div>
<button name='btn_submit'>send</button
<br clear="all" /><br clear="all" />
</div>
</form>
file2.php - code that does the sub category
if($_REQUEST['parent_id'])
{ echo $id = $_REQUEST['parent_id'];
$count = $catList->categoryCount($id);
if($count > 0)
{ echo '<select name="sub_category" class="parent">
<option value="" selected="selected">-- Sub Category --</option>';
foreach($catList->catArrayResults() AS $key2 => $value2)
{ if($value2['node_parent'] == $id )
{ echo '<option value="' . $value2['node_inx'] . '">' . $value2['node_name'] . '</option>'; }
}
echo '</select>';
}
}
javascript code that does the subcategory
$(document).ready(function() {
//$('#loader').hide();
$('.parent').livequery('change', function() {
$(this).nextAll('.parent').remove();
$(this).nextAll('label').remove();
$('#show_sub_categories').append('<img src="loader.gif" style="float:left; margin-top:7px;" id="loader" alt="" />');
$.post("get_chid_categories.php", {
parent_id: $(this).val(),
var str = $( ".parent" ).serialize(),
}, function(response){
setTimeout("finishAjax('show_sub_categories', '"+escape(response)+"')", 400);
});
return false;
});
});
function finishAjax(id, response)
{ $('#loader').remove();
$('#'+id).append(unescape(response));
}