Bug Tracker

Modify

Ticket #3953 (closed bug: duplicate)

Opened 4 years ago

Last modified 4 years ago

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

comment:1 Changed 4 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 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to duplicate

This is a dup of #3104.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.