0

I am attempting to use a variable to collect information from an object. I am a php programmer and im not very good with javascript yet.

var priceobj= {'Youth Small':'0', 'Youth Meduim':'0', 'Youth Large':'0','Adult Small':'0','Adult Medium':'0','Adult Large':'0','Adult XL':'0','Adult XXL':'2','Adult XXXL':'3'};

var os0 = $('#os0').val(); // value will be one of the options in priceobj

var value = priceobj.os0 // this should read 0,2,3 depending on the value of os0

1 Answer 1

3

Try

var value = priceobj[os0];

os0 isn't a key, it's a value which represents a key. The way you called it, it would have to be a key.

Sign up to request clarification or add additional context in comments.

Comments

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.