I have 2 select drop downs. Using jquery selector syntax i should be able to get the value of each drop down when i change them.
It works for the first select box, but does not access the second, that is why it comes up with the same value.
Any ideas why this is happening? I remember accessing this by class a while ago and it worked just fine.
Creating two objects with the same class value, does create a collection?
For what you are trying to do, it will be better to get the objects by id property instead, setting them different values.
Thanks for your reply, pablogo
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.
//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();
What does the alert say?
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"
//getting "text" from select node
// o = instance of a Select node
That's means that you should access the option collection for the retriving the text actually being displayed on the select.
Interesting. Thanks for the information.