Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#8570 closed bug (fixed)

.val method returning "on" for dynamically created radio buttons in ie9

Reported by: garybentley Owned by: timmywil
Priority: high Milestone: 1.6
Component: attributes Version: 1.5.1
Keywords: ie9 Cc:
Blocked by: Blocking:


  • 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);


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 6 years ago by anonymous

Sorry, didn't see the jsfiddle requirement.


comment:2 Changed 6 years ago by rwaldron

  • Component changed from unfiled to attributes
  • Owner set to garybentley
  • Status changed from new to pending

Please take a look at this fiddle and confirm the output: http://jsfiddle.net/rwaldron/sGWVJ/2/

comment:3 Changed 6 years ago by danheberden

comment:4 Changed 6 years ago by dmethvin

  • Keywords ie9 added

comment:5 Changed 6 years ago by dmethvin

  • Priority changed from undecided to high
  • Status changed from pending to open

comment:6 Changed 6 years ago by timmywil

  • Milestone changed from 1.next to 1.6
  • Owner changed from garybentley to timmywil
  • Status changed from open to assigned

comment:7 Changed 6 years ago by timmywil

pull request for review

comment:8 Changed 6 years ago by timmywil

  • Resolution set to fixed
  • Status changed from assigned to 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

Note: See TracTickets for help on using tickets.