Bug Tracker

Opened 15 years ago

Closed 15 years ago

Last modified 11 years ago

#2652 closed enhancement (fixed)

val() returns an empty string in IE6/7

Reported by: kowcik Owned by: flesler
Priority: minor Milestone: 1.3
Component: core Version: 1.2.6
Keywords: val, select selected Cc:
Blocked by: Blocking:


See the attached example.

Attachments (2)

val.html (822 bytes) - added by kowcik 15 years ago.
Test case from jQuery documentation
val[5790].diff (843 bytes) - added by flesler 15 years ago.

Download all attachments as: .zip

Change History (8)

Changed 15 years ago by kowcik

Attachment: val.html added

Test case from jQuery documentation

comment:1 Changed 15 years ago by flesler

Resolution: invalid
Status: newclosed

So.. the options don't have a 'value' attribute, it's expected that you get and empty string as return.

I'll close as invalid, but please reopen if you have anything else to say, do include more details when you do that (better test case and tell us what you expect the return to be, etc).

comment:2 Changed 15 years ago by kowcik

Resolution: invalid
Status: closedreopened

In IE val() returns empty strings, whereas in Firefox the value is returned also when there's no value attributed. This should the desired behaviour, because val seems to be an abstraction to access inputs values as they would be submitted to the server. Also, there is a specific line in jQuery code that tries to retrieve values from options, but for some reason this value is not returned later. Generally option.text is the right property to read from in IE.

//val function source code

if ( option.selected ) {
// Get the specifc value for the option
value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;

comment:3 Changed 15 years ago by flesler

Owner: set to flesler
Status: reopenednew

comment:4 Changed 15 years ago by flesler

Status: newassigned

comment:5 Changed 15 years ago by flesler

need: PatchCommit
Priority: majorminor
Type: bugenhancement

val() is meant to be used on selects, not on options. If you call it on a select, it will return the value of the selected options, or an array if it's "multiple".

Still.. I pulled out a patch, I'll ask for opinions to see if it should be applied or not.

Changed 15 years ago by flesler

Attachment: val[5790].diff added

comment:6 Changed 15 years ago by flesler

Resolution: fixed
Status: assignedclosed

Fixed and added some tests at [5793].

Note: See TracTickets for help on using tickets.