#8570 closed bug (fixed)
.val method returning "on" for dynamically created radio buttons in ie9
Reported by: | garybentley | Owned by: | Timmy Willison |
---|---|---|---|
Priority: | high | Milestone: | 1.6 |
Component: | attributes | Version: | 1.5.1 |
Keywords: | ie9 | Cc: | |
Blocked by: | Blocking: |
Description
- jquery version: 1.5.1
- browser version: IE 9.0.8112.16421 (other browsers not affected)
- os + version: Windows 7
If you dynamically create a radio button via "createElement" and then use the :checked selector and the val method to retrieve the value "on" is returned in ie9. This doesn't happen with a radio button created via HTML.
Test code:
<div id="test"></div><input type="submit" onclick="window.alert (jQuery('#test input:checked').val ());" value="Click Me!" /><script src="/js/jquery-1.5.1.js"></script><script> jQuery.noConflict (); var el = window.document.createElement ('input'); el.setAttribute ('name', 'hello'); el.setAttribute ('value', 'world'); el.setAttribute ('type', 'radio'); jQuery('#test').append (el); </script>
The expected output is "world" but "on" is returned.
If you use standard html such as:
<input type="radio" name="hello" value="world" />
Then "world" is returned as expected.
This problem doesn't happen in ie8 but in ie8 and below you have to use createElement with the full html specified for the element.
Change History (8)
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
Component: | unfiled → attributes |
---|---|
Owner: | set to garybentley |
Status: | new → pending |
Please take a look at this fiddle and confirm the output: http://jsfiddle.net/rwaldron/sGWVJ/2/
comment:4 Changed 13 years ago by
Keywords: | ie9 added |
---|
comment:5 Changed 13 years ago by
Priority: | undecided → high |
---|---|
Status: | pending → open |
comment:6 Changed 12 years ago by
Milestone: | 1.next → 1.6 |
---|---|
Owner: | changed from garybentley to Timmy Willison |
Status: | open → assigned |
comment:8 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Landing pull request [337](https://github.com/jquery/jquery/pull/337). Value of radio inputs resets when type is set after the value in all IEs. Fixes #8570 ([bug](http://bugs.jquery.com/ticket/8570)).
Changeset: 3ac9eb7ce37b461a34e303e8b77aa544d313441c
Sorry, didn't see the jsfiddle requirement.
http://jsfiddle.net/sGWVJ/