Skip to main content

Bug Tracker

Side navigation

#14930 closed bug (notabug)

Opened March 28, 2014 09:01PM UTC

Closed April 04, 2014 11:29PM UTC

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

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>' +

'</select>');

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

Attachments (0)
Change History (4)

Changed April 04, 2014 01:42PM UTC by mediremi comment:1

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

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

Changed April 04, 2014 01:47PM UTC by m_gol comment:2

owner: → 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:

Changed April 04, 2014 08:12PM UTC by gibson042 comment:3

_comment0: 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 [http://api.jquery.com/val/#val documentation].1396642674778263

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: http://jsfiddle.net/9T4Lq/2/

Changed April 04, 2014 11:29PM UTC by dmethvin comment:4

resolution: → notabug
status: pendingclosed