Bug Tracker

Modify

Ticket #2551 (closed bug: fixed)

Opened 6 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

Description

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>
</select>
</form>
<input type="button" onclick="mc()">
<script>
function mc()
         {document.kk.reset();
          alert($('#kkk')[0].value);
          alert($('#kkk').val());
         }
</script>

Attachments

index.html Download (2.1 KB) - added by tinyfly 4 years ago.
Test case alerting the values returned from both jQuery and DOM methods

Change History

comment:1 Changed 5 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 4 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.

Changed 4 years ago by tinyfly

Test case alerting the values returned from both jQuery and DOM methods

comment:3 Changed 4 years ago by john

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

Duplicate: #4984

comment:4 Changed 4 years ago by dmethvin

  • Component changed from core to attributes

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

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

This bug no longer exists

Tested in IE6 & 7

 http://jsfiddle.net/rwaldron/umpRA/3/

comment:6 in reply to: ↑ 5 Changed 3 years ago by scott.gonzalez

  • Status changed from closed to reopened
  • Resolution worksforme deleted

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 3 years ago by shadedecho

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

 https://connect.microsoft.com/IE/feedback/details/637847/select-elements-options-improperly-reset-after-form-reset

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

 http://test.getify.com/test-ie-form-reset-select.html

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 3 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 3 years ago by shadedecho (previous) (diff)

comment:9 Changed 3 years ago by jitter

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

comment:10 Changed 3 years ago by jitter

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

comment:12 Changed 3 years ago by rwaldron

  • Owner changed from jitter to rwaldron

comment:13 Changed 3 years ago by rwldrn

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

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

Changeset: 43a41ba7ecef732b48dcfc930fa9df8835fc4944

comment:14 Changed 3 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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.