Bug Tracker

Ticket #13514 (closed bug: fixed)

Opened 20 months ago

Last modified 14 months ago

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

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

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.

Change History

comment:1 Changed 20 months ago by dmethvin

  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to attributes
  • Milestone changed from None to 1.9.2

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.

comment:2 Changed 20 months ago by andre.brunnsberg@…

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.

comment:3 Changed 20 months ago by gibson042

comment:4 Changed 19 months ago by ruado1987

  • Status changed from open to closed
  • Resolution set to fixed

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

comment:5 Changed 19 months ago by ruado1987

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

Changeset: 48d71d0c3e53d1bb1688fc6c0593b008ced3403b

comment:6 Changed 19 months ago by gibson042

#13650 is a duplicate of this ticket.

comment:7 Changed 17 months ago by dmethvin

  • Milestone changed from 1.9.2 to 1.10/2.0

Bulk update to milestone 1.10/2.0

comment:8 Changed 14 months ago by anonymous

Seems like it is happening again on FF on a Mac. When setting $el.val(nonexistence) it creates an empty first option.

Note: See TracTickets for help on using tickets.