Ticket #3953 (closed bug: duplicate)
val() on select isn't correct... ?
| Reported by: | Just | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.3.1 |
| Component: | core | Version: | 1.3 |
| Keywords: | val value text conflict | Cc: | |
| Blocking: | Blocked by: |
Description
In the jQuery libray there's the next code (line 462 of jQuery 1.3.1) :
<js>
jQuery( "option", this ).each(function(){
this.selected = (jQuery.inArray( this.value, values ) >= 0 jQuery.inArray( this.text, values ) >= 0);
});
</js>
So in fact it give the selected attribute if the value attribute OR the inner text of the option match the value. I think that's not the true way to do it. Because if an option element have a value attribute the inner text should be ignore !
i.e. a select box filled with item created dynamically by the user (so each item have a "name" field completed by the user and a "id" field completed automaticaly by the system - a database autoincrement). So we could have this DOM : <dom> <select> <option value="1">6</option> <option value="2">5</option> <option value="3">4</option> <option value="4">3</option> </select> </dom> For this list if I do $('select').val(3);
The two last items are selected... instead of only one ! The real one which have the value 4.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

A the end of my post : I would say "The real one which have the value 3" not "the value 4".