Skip to main content

Bug Tracker

Side navigation

#5555 closed bug (worksforme)

Opened November 26, 2009 01:38PM UTC

Closed September 28, 2010 09:58PM UTC

using val(val) to set selected option of select list selects wrong option

Reported by: anentropic Owned by:
Priority: major Milestone: 1.4.3
Component: attributes Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

I have a select list like:

<select name="sizes" id="mysel">

<option value="3">3</option>

<option value="4">3.5</option>

<option value="5">4</option>

<option value="6">4.5</option>

<option value="7">5</option>


I want to set the selected option by value (which correspond to ids in the db):


This selects the option with the text label 4, whose value is actually 5.

This is surely incorrect behaviour.

Attachments (0)
Change History (4)

Changed November 26, 2009 01:40PM UTC by anentropic comment:1

..especially since $('#mysel').val() returns the value, *not* the label... so the val method of select lists works differently depending on whether you're getting or setting!

Changed November 26, 2009 01:47PM UTC by anentropic comment:2

Well, I just read a mailing list post explaining what jQuery is doing here:

Apparently it's even worse... the behaviour is pretty much unpredictable, it could return value OR label depending on the structure of your list. It seems the method has been optimised for speed ahead of utility and common sense...

Changed June 13, 2010 07:00PM UTC by dmethvin comment:3

component: unfiledattributes

Changed September 28, 2010 09:58PM UTC by john comment:4

resolution: → worksforme
status: newclosed

This was resolved in 1.4. More tests here to confirm: