Skip to main content

Bug Tracker

Side navigation

#3953 closed bug (duplicate)

Opened January 22, 2009 01:22PM UTC

Closed January 28, 2009 12:14AM UTC

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:
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.

Attachments (0)
Change History (2)

Changed January 22, 2009 01:32PM UTC by Just comment:1

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

Changed January 28, 2009 12:14AM UTC by dmethvin comment:2

resolution: → duplicate
status: newclosed

This is a dup of #3104.