Dependent Dropdowns Not Working, 2nd Dropdown Not Loading
I need help with this one, i dont know why the sub cat wont load. but the first dropdown loads all the queries. i just dont know why it wont work with the 2nd one. here is my index
Solution 1:
Try doing a simple AJAX
function:
<scripttype="text/javascript">functionAjaxCall(ElemVal,PlaceId) {
$.ajax({
url: "loadsubcat.php?parent_cat="+$(ElemVal).val(),
success: function(result) {
$("#"+ PlaceId).html(result);
}
});
}
$(document).ready(function() {
$("#parent_cat").change(function() {
$("#sub-cat-load").html('<div id="loader"><img src="img/loading.gif" alt="loading subcategory" /></div>');
AjaxCall(this,'sub-cat-load');
});
});
</script>
sub_cat container
<label>Sub Category</label><!-- NOTICE THIS PART --><divid="sub-cat-load"></div>
loadsubcat.php
<?phpinclude('config.php');
// You may want to sanitize this variable$parent_cat = $_GET['parent_cat'];
$query = mysql_query("SELECT city FROM zipcodes WHERE major_area = {$parent_cat}") ordie(mysql_error()); ?><selectname="sub_cat"id="sub_cat"><?phpwhile($row = mysql_fetch_array($query)) { ?><optionvalue="<?phpecho$row[city]; ?>"><?phpecho$row[city]; ?></option><?php
} ?></select>
Post a Comment for "Dependent Dropdowns Not Working, 2nd Dropdown Not Loading"