0

I'm so sorry i don't really know how i can title this question but i believe with little explanation you guys will know what i wanted to achieve. below is my code

var brandObj = $.parseJSON(\$brand);
  var listItems= "";
  for (var i = 0; i < brandObj.length; i++){
    listItems+= "<option value='" + brandObj[i].name+ "'>" + brandObj[i].name + "</option>";
  }
  $("#brand-select").append(listItems);

The json object has many attribute like brandObj[i].name, brandObj[i].id, brandObj[i].color,brandObj[i].size, and so on, so now i need to check according to users input to know which attribute i will show up in dropdown menu, i try to assign the attribute to a variable so i can dynamically change the variable but it's not working, i tried this

var brandObj = $.parseJSON(\$brand);
  var listItems= "";
 var value = name
  for (var i = 0; i < brandObj.length; i++){
    listItems+= "<option value='" + brandObj[i].+value+ "'>" + brandObj[i].+value + "</option>";
  }
  $("#brand-select").append(listItems);

i replace the name attribute with variable but not working any one to help me on this thanks

sam
  • 853
  • 3
  • 19
  • 50
  • 1
    `brandObj[i][value]` – haim770 Aug 09 '16 at 13:19
  • ...and that's not JSON. You stopped dealing with JSON after the very first line of code above.JSON is a *textual notation* for data exchange. [(More)](http://stackoverflow.com/a/2904181/157247) If you're dealing with JavaScript source code, and not dealing with a *string*, you're not dealing with JSON. – T.J. Crowder Aug 09 '16 at 13:19
  • David: Beat me by 23 seconds (had to go find the link). :-) – T.J. Crowder Aug 09 '16 at 13:21
  • ok thank you guys really appreciate this – sam Aug 09 '16 at 13:25

0 Answers0