jquery - How to select a specific option in a dropdown that has multiple instances? -


here basic example of trying achieve :

<select name="userid" id="userid"> <option value="1">charles</option> <option value="2">mike</option> <option value="3">jeff</option> <option value="4">kevin</option> </select>  <select name="userid" id="userid"> <option value="1">charles</option> <option value="2">mike</option> <option value="3">jeff</option> <option value="4">kevin</option> </select>  <select name="userid" id="userid"> <option value="1">charles</option> <option value="2">mike</option> <option value="3">jeff</option> <option value="4">kevin</option> </select> 

for instance, select third option (jeff) of second "userid" dropdown. know how unique dropdown, can't work multiple dropdowns having same id.

i thought able following line:

$("input[id=userid]").eq(1).val("3"); 

.. doesn't work.

any idea?

thank much

charles

you can't. dom element's id supposed globally unique. having same id="userid" bit 3 times broken html. instead, use:

<select name="userid" class="userid"> ... </select> 

then can do:

$('select.userid').<whatever jquery want>; 

and you'll set.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -