I have three drop down menus that query a MYSQL database depending on what a user selects. One of the menus is dynamic and but I can’t get it to return data – the other two work fine. I think i need to catch the JS onchange event and then pass it to PHP in order to run the query but I am going in circles at present.
Below is what i am trying to do. All the values are stored in the <head> section – I have added my query and select html and on change event below.
$category=$_POST['Category'];
$subcategory=$_POST['Subcategory'];
$destination=$_POST['Destination'];
$result = mysql_query("SELECT * FROM travel WHERE Category='$category'
AND Subcategory='$subcategory' AND Destination='$destination'")
or die(mysql_error());
$row = mysql_fetch_assoc( $result ) ;
<select name="subcategory" id="subcategory onchange="javascript:
dropdownlist(this.options[this.selectedIndex].value)">
<option value="">Select Sub-Category</option>
Try this jQuery:
I’ll leave you to do the server bit – you’ll need
json_encode(). Have fun!