Add certain values from JSON object to javascript array -


update: i've tried suggestions in comments , it's still not working. have no idea why. i've consolidated single loop , fixed syntax errors noted. here's code looks now:

    $(function() {    $("#json-one").change(function() {      var $dropdown = $(this);      $.getjson("washroutines.json", function(data) {        var vals = [];       var $jsontwo = $("#json-two"); $jsontwo.empty();                (var = 0; < data.length; i++){         if (data[i].make === $dropdown.val()) {           $jsontwo.append("<option value=\"" + data[i].model + "\">" + data[i].model + "</option>");         }       }      });   });  }); 

any additional appreciated!

original question:

i'm trying create dependent drop down menus using json object, , i'm having trouble getting second menu populate based on first. when first menu changes, second goes bunch of "undefined"s.

    $.getjson("washroutines.json", function(data) {            var vals = [];  (i = 0; < data.length; i++){  if (data.make = $dropdown.val()) {    vals.push(data.model);    }   }        var $jsontwo = $("#json-two");       $jsontwo.empty();    (i = 0; < vals.length; i++){    $jsontwo.append("<option value\"" + vals[i] + "\">" + vals[i] + "</option>"); } 

please use small words when explaining things me, i'm new @ this!

contents of json:

[{"make":"maytag","model":"bravos","prewashcycle":"whitest whites"}, {"make":"maytag","model":"awesome","prewashcycle":"awesome whitest whites"}, {"make":"whirlpool","model":"cabrio","prewashcycle":"extra heavy"}, {"make":"kenmore","model":"elite","prewashcycle":"awesome"}] 

try changing loop this

for (var = 0; < data.length; i++){   if (data[i].make === $dropdown.val()) {     vals.push(data[i].model);   } } 

Comments