Skip to main content

Bug Tracker

Side navigation

#8512 closed enhancement (patchwelcome)

Opened March 13, 2011 01:58AM UTC

Closed March 18, 2011 01:19AM UTC

Last modified March 14, 2012 05:37PM UTC

jQuery("SELECT").val(null) : inconsistent results in different browsers

Reported by: shehriyari Owned by: shehriyari
Priority: low Milestone: 1.next
Component: attributes Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:
Description

http://jsfiddle.net/jf7t2/1/

Please run it on the latest versions of all browsers, and see for yourself. When the button is clicked, on:

1. on WebKit browsers (Chrome, Safari) it just doesn't select anything, instead creates some ghostly empty option

2. on Firefox and Opera, it works the way I expect and want it to work, de-selects all options of the element

3. on Explorer, it does nothing

jQuery 1.5.1 source code also tells us that, in this case jQuery sets selectedIndex = -1.

http://stackoverflow.com/questions/5286424/jqueryformelement-valnull-inconsistent-results-in-different-browsers/5286643#5286643

But since browsers mess it up in this case. Shouldn't jQuery force it to behave the way Firefox and Opera does, de-select all child options?

Thanks.

Attachments (0)
Change History (3)

Changed March 13, 2011 03:00AM UTC by dmethvin comment:1

component: unfiledattributes
owner: → shehriyari
priority: undecidedlow
status: newpending
type: bugenhancement

There is no documented behavior for .val(null), are you asking for that to be an enhancement to select no options then? The W3C has this to say about the case where nothing is selected initially:

http://www.w3.org/TR/html401/interact/forms.html#h-17.6

If no OPTION element has the selected attribute set, user agent behavior for choosing which option is initially selected is undefined. Note. Since existing implementations handle this case differently, the current specification differs from RFC 1866 ([RFC1866] section 8.1.3), which states: The initial state has the first option selected, unless a SELECTED attribute is present on any of the <OPTION> elements. Since user agent behavior differs, authors should ensure that each menu includes a default pre-selected OPTION.

It's not clear whether browsers want you to deselect all options on a select-one element, but the behavior seems to be poorly defined in any case.

Changed March 14, 2011 02:24AM UTC by shehriyari comment:2

_comment0: I would prefer that, yes, to select no options. \ \ HOWEVER, my wishes are irrelevant: Although it is NOT documented, the CODE is written that way [jQuery source 1.5.1 - check the stackoverflow.com discussion I referred you to, in original report]. What I say, is that you should make a decision, and implement it. Having selectedIndex = -1 doesn't solve problems, it creates them. jQuery's primary objective (I believe) should be "to be standards-compliant AND cross-browser, useful tool that DOES function", not just "to be standards-compliant tool that follows those standards to no end". selectedIndex = -1 doesn't serve anyone... \ \ And again, YES, I would recommend having all options de-selected. That would solve a lot of problems and would be quite useful shortcut for us, developers. \ \ Thanks for all the effort you guys putting forward, jQuery is an awesome tool! Good luck!1300069559869788
_comment1: I would prefer that, yes, to select no options. \ \ HOWEVER, my wishes are irrelevant: Although it is NOT documented, the CODE is written that way [jQuery source 1.5.1 - check the stackoverflow.com discussion I referred you to, in original report]. What I say, is that you should make a decision, and implement it. Having selectedIndex = -1 doesn't solve problems, it creates them. jQuery's primary objective (I believe) should be "to be standards-compliant AND cross-browser, useful tool that DOES function", not just "to be standards-compliant tool that follows those standards blindly, to no end". selectedIndex = -1 doesn't serve anyone... \ \ And again, YES, I would recommend having all options de-selected. That would solve a lot of problems and would be quite useful shortcut for us, developers. \ \ Thanks for all the effort you guys putting forward, jQuery is an awesome tool! Good luck!1300069652782598
_comment2: I would prefer that, yes, to select no options. \ \ HOWEVER, my wishes are irrelevant: Although it is NOT documented, the CODE is written that way [jQuery source 1.5.1 - check the stackoverflow.com discussion I referred you to, in original report]. What I say, is that you should make a decision, and implement it. Having selectedIndex = -1 doesn't solve problems, it creates them. jQuery's primary objective (I believe) should be "to be standards-compliant AND cross-browser, useful tool that DOES function", not just "to be standards-compliant tool that follows those standards blindly, to no end". selectedIndex = -1 doesn't serve anyone... \ \ And again, YES, I would recommend having all options de-selected. That would solve a lot of problems and would be quite useful shortcut for us, developers. \ \ Thanks for all the effort you guys putting forward, jQuery is an awesome tool! Good luck! \ \ P.S.: That's why I would call this report a BUG, not ENHANCEMENT, since this little feature doesn't do anything useful for front-end designers.1300090791727077
status: pendingnew

I would prefer that, yes, to select no options.

HOWEVER, my wishes are irrelevant: Although it is NOT documented, the CODE is written that way [jQuery source 1.5.1 - check the stackoverflow.com discussion I referred you to, in original report]. What I say, is that you should make a decision, and implement it. Having selectedIndex = -1 doesn't solve problems, it creates them. jQuery's primary objective (I believe) should be "to be standards-compliant AND cross-browser, useful tool that DOES function", not just "to be standards-compliant tool that follows those standards blindly, to no end". selectedIndex = -1 doesn't serve anyone...

And again, YES, I would recommend having all options de-selected. That would solve a lot of problems and would be quite useful shortcut for us, developers.

Thanks for all the effort you guys putting forward, jQuery is an awesome tool! Good luck!

P.S.: That's why I would call this report a BUG, not an ENHANCEMENT, since this little feature doesn't do anything useful for front-end designers.

Changed March 18, 2011 01:19AM UTC by rwaldron comment:3

description: \ http://jsfiddle.net/jf7t2/1/ \ \ Please run it on the latest versions of all browsers, and see for yourself. When the button is clicked, on: \ \ 1. on WebKit browsers (Chrome, Safari) it just doesn't select anything, instead creates some ghostly empty option \ 2. on Firefox and Opera, it works the way I expect and want it to work, de-selects all options of the element \ 3. on Explorer, it does nothing \ \ jQuery 1.5.1 source code also tells us that, in this case jQuery sets selectedIndex = -1. \ \ http://stackoverflow.com/questions/5286424/jqueryformelement-valnull-inconsistent-results-in-different-browsers/5286643#5286643 \ \ But since browsers mess it up in this case. Shouldn't jQuery force it to behave the way Firefox and Opera does, de-select all child options? \ \ Thanks.http://jsfiddle.net/jf7t2/1/ \ \ Please run it on the latest versions of all browsers, and see for yourself. When the button is clicked, on: \ \ 1. on WebKit browsers (Chrome, Safari) it just doesn't select anything, instead creates some ghostly empty option \ 2. on Firefox and Opera, it works the way I expect and want it to work, de-selects all options of the element \ 3. on Explorer, it does nothing \ \ jQuery 1.5.1 source code also tells us that, in this case jQuery sets selectedIndex = -1. \ \ http://stackoverflow.com/questions/5286424/jqueryformelement-valnull-inconsistent-results-in-different-browsers/5286643#5286643 \ \ But since browsers mess it up in this case. Shouldn't jQuery force it to behave the way Firefox and Opera does, de-select all child options? \ \ Thanks.
resolution: → patchwelcome
status: newclosed