Bug Tracker

Ticket #8570 (closed bug: fixed)

Opened 3 years ago

Last modified 2 years ago

.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:
Blocking: Blocked by:

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

comment:1 Changed 3 years ago by anonymous

Sorry, didn't see the jsfiddle requirement.

 http://jsfiddle.net/sGWVJ/

comment:2 Changed 3 years ago by rwaldron

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

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

comment:3 Changed 3 years ago by danheberden

comment:4 Changed 3 years ago by dmethvin

  • Keywords ie9 added

comment:5 Changed 3 years ago by dmethvin

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

comment:6 Changed 3 years ago by timmywil

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

comment:7 Changed 3 years ago by timmywil

 pull request for review

comment:8 Changed 3 years ago by timmywil

  • Status changed from assigned to closed
  • Resolution set to fixed

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.