Side navigation
#1008 closed bug (fixed)
Opened February 28, 2007 05:50PM UTC
Closed September 15, 2007 01:29PM UTC
Last modified March 15, 2012 01:16AM UTC
IE7 fails $('select#Choice :selected').val();
Reported by: | reisac | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.2 |
Component: | core | Version: | 1.1.4 |
Keywords: | select option | Cc: | |
Blocked by: | Blocking: |
Description
I have something like:
<select id=Choice><option selected>test</option>..</select>
I expect '''$('select#Choice :selected').val();
to return test''' ''(HTML4 reference: In the absence of a VALUE attribute, the value is the content of the OPTION element)''.
This works in Firefox, but not in IE7.
Workaround1: add a value='test' tag to the option.
Workaround2: use $('select#Choice :selected').text();
Both workarounds are not really conform.
Attachments (0)
Change History (2)
Changed March 07, 2007 11:21PM UTC by comment:1
Changed September 15, 2007 01:29PM UTC by comment:2
description: | I have something like:\ <select id=Choice><option selected>test</option>..</select>\ \ I expect '''$('select#Choice :selected').val();''' \ to return '''test''' ''(HTML4 reference: In the absence of a VALUE attribute, the value is the content of the OPTION element)''.\ This works in Firefox, but not in IE7.\ \ Workaround1: add a value='test' tag to the option.[[BR]]\ Workaround2: use $('select#Choice :selected').text(); \ \ Both workarounds are not really conform. → I have something like: \ <select id=Choice><option selected>test</option>..</select> \ \ I expect '''$('select#Choice :selected').val();''' \ to return '''test''' ''(HTML4 reference: In the absence of a VALUE attribute, the value is the content of the OPTION element)''. \ This works in Firefox, but not in IE7. \ \ Workaround1: add a value='test' tag to the option.[[BR]] \ Workaround2: use $('select#Choice :selected').text(); \ \ Both workarounds are not really conform. |
---|---|
milestone: | 1.1.3 → 1.2 |
need: | → Review |
resolution: | → fixed |
status: | new → closed |
version: | 1.1.2 → 1.1.4 |
In jQuery 1.2 should should now just use: $("select#Choice").val();
This is also reported in ticket 1030. For reference, the val() method makes no attempt at solving cross-browser issues like this. It simply returns the current value of the element's value property. FF implicitly promotes an option element's text to the value property if the value attribute is missing. Your quote from the HTML spec references how form data should be *submitted*. val() does not submit data.