Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#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 anonymous

Sorry, didn't see the jsfiddle requirement.

http://jsfiddle.net/sGWVJ/

comment:2 Changed 13 years ago by Rick Waldron

Component: unfiledattributes
Owner: set to garybentley
Status: newpending

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

comment:3 Changed 13 years ago by danheberden

comment:4 Changed 13 years ago by dmethvin

Keywords: ie9 added

comment:5 Changed 13 years ago by dmethvin

Priority: undecidedhigh
Status: pendingopen

comment:6 Changed 12 years ago by Timmy Willison

Milestone: 1.next1.6
Owner: changed from garybentley to Timmy Willison
Status: openassigned

comment:7 Changed 12 years ago by Timmy Willison

pull request for review

comment:8 Changed 12 years ago by Timmy Willison

Resolution: fixed
Status: assignedclosed

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.