#1008 closed bug (fixed)
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 (last modified by )
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.
Change History (2)
comment:1 Changed 16 years ago by
comment:2 Changed 15 years ago by
Description: | modified (diff) |
---|---|
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();
Note: See
TracTickets for help on using
tickets.
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.