I am trying to dynamically change the options available to a user. A user will choose either 1 or 2. Once they choose a value, I need to load the options associated with that value. Currently, i have the following:
var json = {'1':[{ 'value':'A', 'text':'Option - A'}, { 'value':'B', 'text':'Option - B'}], '2':[{ 'value':'A', 'text':'Choice - A'}, { 'value':'B', 'text':'Choice - B'}]};
var userWants = '1';
alert(json[userWants]);
Oddly, the alert window just displays ,
. I don't understand why. What am I doing wrong?
Alerts cannot display
JSON
objects in their natural form. Try logging insteadAlso, see how to alert javascript object