Hi All,
I’m building a form select box that’s related to a prior select box. When a user selects, a brand from a drop down select box, the second drop down select box then populates with related data.
The json data is returned from a database query and looks like this:
{“COLUMNS”:[“MODEL”],“DATA”:[[“1000 S, SF, ST”],[“1000 S, SF, ST”],[“1000 S, SF, ST”],[“1000 S, SF, ST”],[“1000 S, SF, ST”]]}
Here’s where I am. When you choose an option in the first drop down, the second drop down clears and the correct data is retrieved. I just can’t get the data to populate the second drop down with the data.
See: http://199.73.57.203/selectsnew.cfm
<script>
$(document).ready(function() {
//first, detect when initial DropDown changes
$(“#make”).change(function() {
//get what they selected
var selected = $(“option:selected”,this).val();
//no matter what, clear the other DD
$(“#models”).children().remove().end().append(“<option value=\”\“>Select a Stinkin Model</option>”);
//now load in new options if I picked a make
if(selected == “”) return;
$.getJSON(“getfitmentdata09.cfc?method=getmotomodels&returnformat=json”,{“make”:selected}, function(res,code) {
var newoptions = “”;
for(var i=0; i<res.length; i++) {
newoptions += “<option value=\”" + res[i].make + “\”>" + res[i].make + “</option>”;
}
$(“#models”).children().end().append(newoptions);
});
});
})
</script>
<form>
<select name=“make” id=“make”>
<option value=“” selected>Please Select… </option>
<option value=“APRILIA”>APRILIA </option>
<option value=“BENELLI”>BENELLI </option>
<option value=“BIMOTA”>BIMOTA </option>
</select>
<label for=“models”>Models</label>
<select name=“models” id=“models”>
<option value=“”>Select a Model</option>
</select>
</form>