Side navigation
#2551 closed bug (fixed)
Opened March 19, 2008 03:23AM UTC
Closed February 10, 2011 10:52PM UTC
Last modified March 13, 2012 01:58PM UTC
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: |
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 (1)
Change History (14)
Changed July 08, 2009 04:00PM UTC by comment:1
Changed December 08, 2009 07:26PM UTC by comment:2
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 December 10, 2009 04:07AM UTC by comment:3
milestone: | 1.2.3 → 1.4 |
---|---|
version: | 1.2.3 → 1.3.2 |
Duplicate: #4984
Changed June 20, 2010 06:00PM UTC by comment:4
component: | core → attributes |
---|
Changed November 07, 2010 12:25AM UTC by comment:5
milestone: | 1.4 → 1.5 |
---|---|
priority: | major → low |
resolution: | → worksforme |
status: | new → closed |
Changed January 24, 2011 03:29PM UTC by comment:6
resolution: | worksforme |
---|---|
status: | closed → reopened |
Replying to [comment:5 rwaldron]:
This bug no longer exists
Your test is invalid. You're checking the value inside the reset event before the form is reset.
Changed January 24, 2011 04:13PM UTC by comment:7
I've filed this as a bug in the IE Connect feedback system:
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.
Changed January 26, 2011 04:24PM UTC by comment:8
_comment0: | 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/485eede4ee4582a8d60438b280d04f4db4aa45f9 → 1296060666826024 |
---|
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
Changed January 27, 2011 12:26PM UTC by comment:9
milestone: | 1.5 → 1.5.1 |
---|---|
owner: | → shadedecho |
status: | reopened → assigned |
version: | 1.3.2 → 1.5rc1 |
Changed February 07, 2011 05:37PM UTC by comment:10
owner: | shadedecho → jitter |
---|---|
version: | 1.5rc1 → 1.5 |
Changed February 10, 2011 10:41PM UTC by comment:11
Changed February 10, 2011 10:41PM UTC by comment:12
owner: | jitter → rwaldron |
---|
Changed February 10, 2011 10:52PM UTC by comment:13
resolution: | → fixed |
---|---|
status: | assigned → closed |
Make sure .val() works after form.reset() in IE. Fixes #2551.
Changeset: 43a41ba7ecef732b48dcfc930fa9df8835fc4944
Changed March 31, 2011 07:26PM UTC by comment:14
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.
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...