Bug Tracker

Opened 9 years ago

Closed 6 years ago

Last modified 5 years ago

#2551 closed bug (fixed)

val() failed after reset form in ie6/ie7

Reported by: diyism Owned by: rwaldron
Priority: low Milestone: 1.5.1
Component: attributes Version: 1.5
Keywords: val() failed after reset form in ie6/ie7 Cc:
Blocked by: Blocking:


Getting value with val() failed after reset form in ie6/ie7:

<form name="kk">
<select id="kkk">
        <option value="cf">cf</option>
        <option value="gf">gf</option>
<input type="button" onclick="mc()">
function mc()

Change History (14)

comment:1 Changed 8 years ago by mickyp

Is there any solution for this issue?

Is it truly a jQuery issue? or it's IE's issue.

I test in firefox and Google Chrome, there is no problem.

I test failed in IE6 and IE8...

comment:2 Changed 7 years ago by tinyfly

Bug? I don't know but it is definitely an IE idiosyncrasy that jQuery could work around.

Here is how it works:

If you don't have a "selected" attribute on one of your options IE defaults to the first option and the DOM properties select.selectedIndex = 0 and option.selected = true.

However if you click an input type="reset" or run the reset method IE reports select.selectedIndex = 0 and option.selected = false.

I think this behavior is undesirable.

Before jQuery gets the value of the selected option it only checks for option.selected. Checking for option.selected
selectedIndex might be a way to get around this.

comment:3 Changed 7 years ago by john

  • Milestone changed from 1.2.3 to 1.4
  • Version changed from 1.2.3 to 1.3.2

Duplicate: #4984

comment:4 Changed 7 years ago by dmethvin

  • Component changed from core to attributes

comment:5 follow-up: Changed 6 years ago by rwaldron

  • Milestone changed from 1.4 to 1.5
  • Priority changed from major to low
  • Resolution set to worksforme
  • Status changed from new to closed

This bug no longer exists

Tested in IE6 & 7


comment:6 in reply to: ↑ 5 Changed 6 years ago by scottgonzalez

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Replying to rwaldron:

This bug no longer exists

Your test is invalid. You're checking the value inside the reset event before the form is reset.

comment:7 Changed 6 years ago by shadedecho

I've filed this as a bug in the IE Connect feedback system:


The (non-jquery) test case I submitted to them is:


Scott noted that setting el.selectedIndex = el.selectedIndex seems to "reset" the options' values properly, so perhaps the jQuery workaround could be to just make that call (what seems like a no-op in all other browsers) right at the beginning of a call to .val() on a select.

comment:8 Changed 6 years ago by shadedecho

turns out the fix only needs to be applied to single-selects, and in fact if applied to multi-selects, breaks them. but the fix was as described, setting selectedIndex=selectedIndex.

patch: https://github.com/getify/jquery/tree/0c67c920757a47d95d24ab1affcb2b54137d390d

Last edited 6 years ago by shadedecho (previous) (diff)

comment:9 Changed 6 years ago by jitter

  • Milestone changed from 1.5 to 1.5.1
  • Owner set to shadedecho
  • Status changed from reopened to assigned
  • Version changed from 1.3.2 to 1.5rc1

comment:10 Changed 6 years ago by jitter

  • Owner changed from shadedecho to jitter
  • Version changed from 1.5rc1 to 1.5

comment:12 Changed 6 years ago by rwaldron

  • Owner changed from jitter to rwaldron

comment:13 Changed 6 years ago by rwldrn

  • Resolution set to fixed
  • Status changed from assigned to closed

Make sure .val() works after form.reset() in IE. Fixes #2551.

Changeset: 43a41ba7ecef732b48dcfc930fa9df8835fc4944

comment:14 Changed 6 years ago by jj_arbaugh@…

FYI - This still happens on IE6 w/ v1.5.1 - had to add browser detection and not have it try to set the value of a select list using "val()" but instead used some old style code to set the selected index. In IE6 this does not require a "reset" action. I don't even have one on my form.

Honestly not worth fixing in my opinion. I had to get help from someone else with an IE 6 browser just to find out what the problem was and add the work around.

Note: See TracTickets for help on using tickets.