Forum

Thread tagged as: Question, Problem

Radio button - set one selected as default

I have a radiobutton input like this:

<perch:content id="content_alignment" type="radio" label="Align image" options="Left, Right, Center">

Can I set one of the options as selected by default?

Tim Kinali

Tim Kinali 0 points

  • 3 years ago
Simon Clay

Simon Clay 127 points

Hi Tim,

I think you should be able to add

value="Left"

To set the default to Left

Thanks, I will try that!

hello, I have an HTML form like

<form name="radio-mc">
    <input type="radio" name="mc" id="radio-1" value="1"> First
    <input type="radio" name="mc" id="radio-2" value="2"> Second
    <input type="radio" name="mc" id="radio-3" value="3"> Third
</form>

I can get the selected value in Chrome by form/input name with the following javascript

document.forms['radio-mc']['mc'].value But in Firefox, the value is undefined.

I would normally think this was a specialty of Chrome but in the Firefox inspector I can see that parent object is an [object NodeList] that has a value property. It's simply not set to anything... seemingly ever.

I cannot use jQuery in this situation. Is there any way to get that one value in vanilla javascript in Firefox (without iterating over the radio buttons like I can in Chrome)?