Skip to main content

Bug Tracker

Side navigation

#14654 closed bug (wontfix)

Opened December 26, 2013 09:59AM UTC

Closed December 26, 2013 04:05PM UTC

get select element value bug

Reported by: frrru@163.com Owned by:
Priority: undecided Milestone: None
Component: attributes Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:
Description

code like this:

selectObj.value = "valueDoesntExists"; //

var val = $(selectObj).val();

then val is null;

it should be "";

look at jquery-1.10.2.js line 4226

Attachments (0)
Change History (1)

Changed December 26, 2013 04:05PM UTC by gibson042 comment:1

component: unfiledattributes
resolution: → wontfix
status: newclosed

.val is documented to return null when no option is selected, and while a case could be made for moving closer to HTML5-specified behavior, I don't find it compelling enough to break our API. I have submitted a pull request to make its behavior even more clear: https://github.com/jquery/api.jquery.com/pull/406

Please use $select.val() || "" if you need an empty string when no option is selected.