#801 ✓works_for_me
Mat Sadler

Element Constructor sets value incorrectly for radio inputs in IE 8

Reported by Mat Sadler | September 15th, 2009 @ 01:39 PM | in 1.7

In IE 8, when creating a new input element using the Element constructor with the type of "radio" the value will be set to "on", no matter what value is passed in with the constructor.

Eg,
var radio = new Element("input", {"value": "test", "type": "radio"}); console.log(radio.value) # writes "on" to IE 8's console, "test" to Safari's

Test case: http://sourcetagsandcodes.com/junk/prototype_radio_bug/index.html

This only seems to be an issue with IE 8

Comments and changes to this ticket

  • syl1101

    syl1101 September 16th, 2009 @ 06:13 PM

    • Tag set to checked, ie, name, radio, value

    Hey Mat!

    I'm experiencing the same in IE7 also.

    The value can be set properly after the creation (before inserting/appending),
    Eg, radioElement.writeAttribute('value','0');

    But the checked attribute cannot be set before insertion, only after it (it shows undefined="checked" in the source),
    Eg, $('radioElementId).checked = true;

    In case it helps somebody: one more nasty thing in IE7 is, it sets the 'name' attribute dynamically for radios in generated source, but does not support it -> the DOM tree will have the original name. Bah...

    May God free us from IE? He will I'm sure! ;)

  • syl1101

    syl1101 September 16th, 2009 @ 06:14 PM

    • Tag changed from checked, ie, name, radio, value to checked, constructor, element, ie, name, radio, value
  • Tobie Langel

    Tobie Langel September 16th, 2009 @ 07:52 PM

    • Milestone set to 1.7
    • State changed from “new” to “bug”
    • Tag changed from checked, constructor, element, ie, name, radio, value to section:dom

    That's a known issue.

    Use Element#setValue in the meantime.

  • T.J. Crowder

    T.J. Crowder November 16th, 2009 @ 04:50 PM

    [responsible:none bulk edit command]

  • Andrew Dupont

    Andrew Dupont October 17th, 2010 @ 11:28 PM

    • State changed from “bug” to “works_for_me”
    • Importance changed from “” to “”

    I can't reproduce this in IE8. In a shell:

    var radio = new Element('input', { type: 'radio', value: 'wtf' });
    radio.value; //-> 'wtf'
    var radio2 = new Element('input', { type: 'radio', value: 'ftw' });
    radio.value; //-> 'ftw'
    

    At first I thought it was because of recent changes that avoid using the tag cache for INPUT elements, but IE8 behaved the same way even after I forced it to use the tag cache.

    I'm going to add the snippet above to the unit tests just in case. If someone can produce a failing test case, please re-open this ticket.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Pages