October 26th, 2007 Using Prototype Javascript to set the value of a radio group
Not that long ago I wrote Using Prototype Javascript to get the value of a radio group, but I keep getting asked how to set the value of a radio group using prototype JS. Here are a couple ways to do just that.
$$("input[type=radio][name='radioGroupName'][value='yourDefaultValue']").writeAttribute("checked", "checked"); $("someRadioGroupMember").writeAttribute("checked", "checked");
Daniel Wintschel Says:
Hmm… The latter was the one I wanted to use, but it didn’t work for me… I used this instead, which worked a-ok.
$(”someRadioGroupMember”).checked = true;
Aaron D. Campbell Says:
What version of Prototype were you using?