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.

2
  • possible duplicate of get value from json with dynamic key Commented Aug 30, 2013 at 7:47
  • this question has been asked multiple times already.... Commented Aug 30, 2013 at 7:47

1 Answer 1

4
var selVal = 'ATF'; // or from an input
alert(jsonObj[selVal]);
Sign up to request clarification or add additional context in comments.

2 Comments

why it is throwing undefined?, if i try like jsonObj.selVal.
@Yadheendran Because it looks for a property "selVal". This does not exist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.