Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 8 years ago

#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 john)

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 13 years ago by malsup

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.

comment:2 Changed 12 years ago by john

Description: modified (diff)
Milestone: 1.1.31.2
need: Review
Resolution: fixed
Status: newclosed
Version: 1.1.21.1.4

In jQuery 1.2 should should now just use: $("select#Choice").val();

Note: See TracTickets for help on using tickets.