Reputation: 989
I currently have 2 drop downs, for example, country and state. I would like to limit the second drop downs contents depending on the selection of the first drop down box. For example if United Kingdom, then US states like Texas or Alaska wouldn't be shown.
At the moment the only solution Ive found is using JS with a bunch of arrays etc. But the problem is the contents of the drop downs are fixed, I need the content of the drop down boxes to be fetched from a MySQL database.
Does anyone know of a method to achieve this?
Thanks
Upvotes: 0
Views: 304
Reputation: 2535
<select name="country" id="sel1">
<option>USA</option>
...
</select>
<select name="state" id="sel2">
Some default options
...
</select>
<script type="text/javascript">
var sel1 = document.getElementById('sel1');
sel1.onchange = function() {
---> ajax functionality to change sel2 contents <----
}
</script>
Upvotes: 1