Bug Tracker

Opened 10 years ago

Closed 9 years ago

#14930 closed bug (notabug)

Setting select .val() to a value that dosen't exist as an option results in undefined in chorme only

Reported by: anonymous Owned by: anonymous
Priority: undecided Milestone: None
Component: unfiled Version: 1.11.0
Keywords: Cc:
Blocked by: Blocking:


When attempting to set a select element with .val() to a value that there is no option for chrome will return undefined where as all other browsers will return the previously selected option value.

Ex: $('body').append('<select id="mySelect">' +

'<option value="1">1</option>' + '<option value="2">2</option>' +


console.log( $("#mySelect").val() ); $("#mySelect").val('2'); console.log( $("#mySelect").val() ); Good $("#mySelect").val('3'); console.log( $("#mySelect").val() ); Undefined in chrome - 2 in all others

Change History (4)

comment:1 Changed 9 years ago by mediremi

I created a test case at http://jsfiddle.net/9T4Lq/1/.

Both Firefox (28 and 31) and Chrome 32 return null, not undefined.

comment:2 Changed 9 years ago by m_gol

Owner: set to anonymous
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!

Additionally, be sure to test against the "jQuery 1.x (edge)" or "jQuery 2.x (edge)" version to ensure the issue still exists—you may need to change this to a specific version depending on the test case.

For the AJAX-related tests you can create a few fiddles and submit requests to addresses with "/show/light" added to the end of the URL; example: http://jsfiddle.net/m_gol/3hwjC/17/show/light/

To get you started, use the appropriate boilerplate:

Open the link and click to "Fork" (in the top menu) to begin.

Also, please read:

Additional resources:

comment:3 Changed 9 years ago by gibson042

I observe null after .val(invalid) in a wide swath of browsers, including Firefox, Chrome, Opera, Safari, and IE>=6, in line with #13514 and the documentation.

Version 0, edited 9 years ago by gibson042 (next)

comment:4 Changed 9 years ago by dmethvin

Resolution: notabug
Status: pendingclosed
Note: See TracTickets for help on using tickets.