#2551 closed bug (fixed)
val() failed after reset form in ie6/ie7
Reported by: | diyism | Owned by: | Rick Waldron |
---|---|---|---|
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 (15)
comment:1 Changed 14 years ago by
comment:2 Changed 13 years ago by
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.
selectedIndex might be a way to get around this. |
Changed 13 years ago by
Attachment: | index.html added |
---|
Test case alerting the values returned from both jQuery and DOM methods
comment:4 Changed 13 years ago by
Component: | core → attributes |
---|
comment:5 follow-up: 6 Changed 12 years ago by
Milestone: | 1.4 → 1.5 |
---|---|
Priority: | major → low |
Resolution: | → worksforme |
Status: | new → closed |
comment:6 Changed 12 years ago by
Resolution: | worksforme |
---|---|
Status: | closed → 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 12 years ago by
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.
comment:8 Changed 12 years ago by
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
comment:9 Changed 12 years ago by
Milestone: | 1.5 → 1.5.1 |
---|---|
Owner: | set to shadedecho |
Status: | reopened → assigned |
Version: | 1.3.2 → 1.5rc1 |
comment:10 Changed 12 years ago by
Owner: | changed from shadedecho to jitter |
---|---|
Version: | 1.5rc1 → 1.5 |
comment:11 Changed 12 years ago by
comment:12 Changed 12 years ago by
Owner: | changed from jitter to Rick Waldron |
---|
comment:13 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Make sure .val() works after form.reset() in IE. Fixes #2551.
Changeset: 43a41ba7ecef732b48dcfc930fa9df8835fc4944
comment:14 Changed 12 years ago by
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...