Javascript Reference
Categories: InputTypeRadio

javascript InputTypeRadio Description

@March 15, 2008, 1:22 a.m.
input (type="radio")Firefox/Netscape/NN 2 IE 3 Chrome/Safari/DOM 1  

  

The radio object is a form control generated with an input element that has a type attribute set to "radio". radio objects related to each other are assigned the same name. This means all like-named radio objects become a collection (array) of radio objects. It may be necessary, therefore, to reference an individual radio button as an item in an array. The entire array, of course, has a length property you can use to assist in looping through all radio objects within the group, if necessary, to find which one is checked, and retrieve that object's value:

var radioGrp = document.forms[0].myRadio;
for (var i = 0; i< radioGrp.length; i++) {
    if (radioGrp[i].checked) {
        alert("The value of the chosen button is " + radioGrp [i].value);
    }
} 
 

Properties and methods listed as follows are for individual radio buttons.

 
HTML Equivalent
 
<input type="radio">
 
Object Model Reference
 
[window.]document.formName.elementName
[window.]document.forms[i].elements[i]
[window.]document.getElementById("elementID")
 
Object-Specific Properties
 
checkeddataFlddataSrcdefaultCheckedform
namestatustypevalue
 
Object-Specific Methods
 
handleEvent[ ]
 
Object-Specific Event Handler Properties
 
HandlerFirefox/Netscape/NNIEChrome/Safari/DOM
onblur642
onclick342
onfocus642
onmousedown442
onmousemove642
onmouseout642
onmouseover642
onmouseup442

Powered by Linode.