I was creating the drop downs dynamically, so i had to assign a dynamic name to each of them when i created them (but still retaining the bind handler to the classname for functionality), and then when i changed them, it would get the name attribute, then allowing me to access their option values independantly from each other.
like this:
$(“.routingselectbox”).live(‘change’,function(){
//get the select name attribute of select
var getname = $(this).attr('name');
//get the currently selected value of it
var currentvalue = $("select[name='"+getname+"'] option:selected").val();
alert(currentvalue);
If i did it that way, the alert would just give me the selected option from the first dropdown. If i changed the second, it would still give me the selected value from the first.
It appears that some html elements can get unique values when using classnames, and others can not so easily using jquery.
However, i did figure it out, and it meant creating a dynamic name for each of the selects and using that to find the selected option (see my previous post).
The wierd thing is, if i can use $(this).attr(‘name’); to get the unique name of the select i just changed, why can’t i do the same for option:selected? different functionality for the selector syntax i guess.
the “option” isn’t a node in pure sense, “options” are collection o objects that are included into “select” nodes.
So, if you want the “text” for a specific “option” (the selected one) you should point to that “option” cause the “select” node do not has a “text” property, so does the “option”
Some example
//getting "text" from select node
// o = instance of a Select node
o.options[o.selectedIndex].text;
That’s means that you should access the option collection for the retriving the text actually being displayed on the select.