Bug Tracker

Opened 9 years ago

Closed 9 years ago

#14654 closed bug (wontfix)

get select element value bug

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: attributes Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:


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

Change History (1)

comment:1 Changed 9 years ago by gibson042

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.

Note: See TracTickets for help on using tickets.