Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #13431
| From | fongemie@gmail.com |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Help! jquery using returned JSON data to write html |
| Date | 2012-04-17 10:53 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <25563245.22.1334685181827.JavaMail.geo-discussion-forums@ynll9> (permalink) |
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 a make in the first drop down, the second 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>
Back to comp.lang.javascript | Previous | Next | Find similar | Unroll thread
Help! jquery using returned JSON data to write html fongemie@gmail.com - 2012-04-17 10:53 -0700
csiph-web