Skip to main content

Bug Tracker

Side navigation

#13514 closed bug (fixed)

Opened February 25, 2013 02:17PM UTC

Closed March 22, 2013 04:49PM UTC

Last modified August 26, 2013 11:21PM UTC

Setting "wrong" value of select-element using .val() is inconsistent in IE9 compared to other browsers

Reported by: andre.brunnsberg@gmail.com Owned by:
Priority: low Milestone: 1.10/2.0
Component: attributes Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:
Description

Check this Fiddle:

http://jsfiddle.net/ECFYX/9/

If the page has a select-element and the value for the select-element is changed using .val(xxx) but with a value that isn't found in the select-element's options then IE9 changes the select element to show an empty option, in all other browsers tested (IE8, IE10, FF, Chrome) it changes the selected value to be the first option.

Attachments (0)
Change History (8)

Changed February 25, 2013 03:05PM UTC by dmethvin comment:1

component: unfiledattributes
milestone: None1.9.2
priority: undecidedlow
status: newopen

Although it seems like a bad idea to depend on this because HTML4 left it to the browser, the HTML5 spec did standardize the case:

If the multiple attribute is absent, whenever there are no option elements in the select element's list of options that have their selectedness set to true, the user agent must set the selectedness of the first option element in the list of options in tree order that is not disabled, if any, to true. -- http://www.w3.org/TR/2009/WD-html5-20090825/forms.html#the-select-element

Compare to the HTML4 language:

If no OPTION element has the selected attribute set, user agent behavior for choosing which option is initially selected is undefined. ... Since user agent behavior differs, authors should ensure that each menu includes a default pre-selected OPTION. -- http://www.w3.org/TR/html401/interact/forms.html#h-17.6

Looks like this was fixed in IE10.

Changed February 26, 2013 07:44AM UTC by andre.brunnsberg@gmail.com comment:2

Also checked that it doesn't help to set one of the select-element's options as selected, IE9 still changes the element to show an empty option.

Changed March 13, 2013 04:28PM UTC by gibson042 comment:3

Relevant discussion is at https://github.com/jquery/jquery/pull/1191

Changed March 22, 2013 04:49PM UTC by ruado1987 comment:4

resolution: → fixed
status: openclosed

Fix #13514: Set selectedIndex to -1 when non-matching value is set on a select. Close gh-1191.

(cherry picked from commit 48d71d0c3e53d1bb1688fc6c0593b008ced3403b)

Changeset: c9ca9bf509edd1dc0a92564210f3f325cc7555b6

Changed March 22, 2013 04:49PM UTC by ruado1987 comment:5

Fix #13514: Set selectedIndex to -1 when non-matching value is set on a select. Close gh-1191.

Changeset: 48d71d0c3e53d1bb1688fc6c0593b008ced3403b

Changed March 22, 2013 04:59PM UTC by gibson042 comment:6

#13650 is a duplicate of this ticket.

Changed May 24, 2013 01:43PM UTC by dmethvin comment:7

milestone: 1.9.21.10/2.0

Bulk update to milestone 1.10/2.0

Changed August 26, 2013 11:21PM UTC by anonymous comment:8

Seems like it is happening again on FF on a Mac.

When setting $el.val(nonexistence) it creates an empty first option.