What method would be best to use to selectively set a single or multiple radio button(s) to a desired setting with JavaScript?
To set a radio button to checked/unchecked, select the element and set its checked property to true or false , e.g. myRadio. checked = true . When set to true , the radio button becomes checked and all other radio buttons with the same name attribute become unchecked.
When you add the radio button, go to the properties for the button, then the Options tab and 'Button checked by default' should be blank, not checked. As for JavaScript in Acro Pro 9, go to Advanced > Document Processing and in the lower part, you will see different options for JavaScript actions. Hope this helps!
Very simple
radiobtn = document.getElementById("theid"); radiobtn.checked = true;
the form
<form name="teenageMutant"> <input value="aa" type="radio" name="ninjaTurtles"/> <input value="bb" type="radio" name="ninjaTurtles"/> <input value="cc" type="radio" name="ninjaTurtles" checked/> </form>
value="cc" will be checked by default, if you remove the "checked" non of the boxes will be checked when the form is first loaded.
document.teenageMutant.ninjaTurtles[0].checked=true;
now value="aa" is checked. The other radio check boxes are unchecked.
see it in action: http://jsfiddle.net/yaArr/
You may do the same using the form id and the radio button id. Here is a form with id's.
<form id="lizardPeople" name="teenageMutant"> <input id="dinosaurs" value="aa" type="radio" name="ninjaTurtles"/> <input id="elephant" value="bb" type="radio" name="ninjaTurtles"/> <input id="dodoBird" value="cc" type="radio" name="ninjaTurtles" checked/> </form>
value="cc" is checked by default.
document.forms["lizardPeople"]["dinosaurs"].checked=true;
now value="aa" with id="dinosaurs" is checked, just like before.
See it in action: http://jsfiddle.net/jPfXS/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With