Bug Tracker

Opened 14 years ago

Closed 14 years ago

#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:
Blocked by: Blocking:


In the jQuery libray there's the next code (line 462 of jQuery 1.3.1) :


jQuery( "option", this ).each(function(){

this.selected = (jQuery.inArray( this.value, values ) >= 0

jQuery.inArray( this.text, values ) >= 0);



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 (2)

comment:1 Changed 14 years ago by Just

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

comment:2 Changed 14 years ago by dmethvin

Resolution: duplicate
Status: newclosed

This is a dup of #3104.

Note: See TracTickets for help on using tickets.