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

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

Hi,

If I dynamically create a radio button via "createElement" and then use the :checked selector and the val method I get "on" returned in ie9.  This doesn't happen with a radio button created via HTML.

Test code:

  1. <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>









Of course the expected output is "world" but "on" is returned.

If you use standard html such as:

  1. <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.

Anyone have any ideas about how to get around this and/or when it(if) will be fixed in jQuery?

Thanks,

Gary


















    • Topic Participants

    • gary