Is this a ligitimate way of determining the selected value of an section/option box with and id of "shirt_size_1221"?
var user_id = '1221';
x = "#shirt_size_" + user_id ;
alert($(x + " option:selected"));
Is this a ligitimate way of determining the selected value of an section/option box with and id of "shirt_size_1221"?
var user_id = '1221';
x = "#shirt_size_" + user_id ;
alert($(x + " option:selected"));
You can get the value of a selected option in a dropdown box by using
var selectList = document.getElementById("shirt_size_1221");
var val = selectList.options[selectList.selectedIndex].text;
No JQuery needed.
Your alert
statement will always show [object]
unless you change it to
alert($(x+' option:selected').val());
And don't worry, this is a good way of getting selected option.
The "proper" way is simply:
var user_id = '1221';
x = "#shirt_size_" + user_id ;
alert($(x).val());