At the moment I using a dynamic select to populate a dropdown. What I would like to do is display a 2nd dropdown with results based on the selection of the first. I have no
it may help, here is a fiddle
http://jsfiddle.net/gZzQr/
that dynamically appends a select
based on the selection of first select
the code is messy and dirty so im not gonna post it here :)
you can have a look at the following to better understand the working
change triggers when the selected value of a select
is changed
is(':empty')
checks whether the div to which the newly created `select
is to be appended is empty or not
http://api.jquery.com/is/
http://api.jquery.com/empty/
Edit i'll give you hints hopefully you'll fill in the rest of code...
first of all what you need to do is handle the change
event of your first drop down and when the value changes you can do an ajax
, get
, post
request to your server, fetch the results and populate the second drop down, here is a useful stackoverflow link that may help you
php dropdown menu population
$("#firstDD").change(function(){
var value = $(this).val();//get the changed value of first dd(drop down)
//now do a post request
$.post("results.php",{data:value},function(data){
//get the values here and populate the second drop down
});
});
in your results.php
get the value from first drop down
$val = $_POST['data'];
//now do the sql queries to fetch desired result
//and echo the results back
echo $results ;
here are some useful links
http://www.prodevtips.com/2008/08/15/jquery-json-with-php-json_encode-and-json_decode/
http://api.jquery.com/jQuery.post/
http://www.factsandpeople.com/facts-mainmenu-5/26-html-and-javascript/89-jquery-ajax-json-and-php