0

I have a json which is generated through php and i assigned it to a JS variable like below,

var jsonObj =  {
    "ATF":["FLV"],
    "Limecase":["FLV"],
    "RCF":["FLV","HTTP","PALM","MOBILE","3GP","H263","F263","WMV"],
    "Wave":["FLV","IPHONE","MOBILE"]
}

And also i have a selectbox in html as below,

<select id="selectbox" data-rel="chosen"> 
    <option value='ATF'>ATF</option>
    <option value='Limespace'>Limespace</option>
    <option value='RCF'>RCF</option>
    <option value='Wave'>Wave</option>
</select>

On changing, i am getting the selected value and passing it as below,

alert(jsonObj.selVal); but alert throws "undefined"

But if i give direct value jsonObj.ATF, it gives FLV.

Please suggest me on this.

NDM
  • 6,731
  • 3
  • 39
  • 52
Raja
  • 3,477
  • 12
  • 47
  • 89
  • possible duplicate of [get value from json with dynamic key](http://stackoverflow.com/questions/17591380/get-value-from-json-with-dynamic-key) – NDM Aug 30 '13 at 07:47
  • this question has been asked multiple times already.... – NDM Aug 30 '13 at 07:47

1 Answers1

4
var selVal = 'ATF'; // or from an input
alert(jsonObj[selVal]);
Dale
  • 10,384
  • 21
  • 34