Opened 9 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: |
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
Change History (4)
comment:1 Changed 9 years ago by
comment:2 Changed 9 years ago by
Owner: | set to anonymous |
---|---|
Status: | new → pending |
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:
- jQuery 1.x http://jsfiddle.net/FrKyN/
- jQuery 2.x http://jsfiddle.net/BenVk/
Open the link and click to "Fork" (in the top menu) to begin.
Also, please read:
- http://blog.jquery.com/2013/04/18/jquery-2-0-released/
- http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/
Additional resources:
- Won't Fix: http://contribute.jquery.org/wont-fix/
- CLA: http://contribute.jquery.org/CLA/
- Style Guide: http://contribute.jquery.org/style-guide/js/
comment:3 Changed 9 years ago by
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/
comment:4 Changed 9 years ago by
Resolution: | → notabug |
---|---|
Status: | pending → closed |
I created a test case at http://jsfiddle.net/9T4Lq/1/.
Both Firefox (28 and 31) and Chrome 32 return
null
, notundefined
.