Snippet Name: Get and set radio buttons with Javascript
Description: Easy functions to get and set radio buttons with Javascript. Super handy!
Comment: (none)
Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: February 27th, 2009
|
// The getRadio(radio) function returns the
// value of the active radio button.
FUNCTION getRadio(radio){
// Parameters:
// "radio" is a radio button object, <formname>.<radiogroup>
// Behavior:
// The value of the active radio button is returned to the caller
FOR(i=0; i<radio.length; i++){
IF(radio[i].checked){
RETURN(radio[i].value);
BREAK;
}
}
}
// The setRadio(radio, value) function sets the
// active radio button that matches the value.
FUNCTION setRadio(radio, value){
// Parameters:
// "radio" is a radio button object, <formname>.<radiogroup>
// "value" is the radio button to activate
// Behavior:
// Sets the active radio button
FOR(i=0; i<radio.length; i++){
IF(radio[i].value == value){
radio[i].checked = TRUE;
} ELSE {
radio[i].checked = FALSE;
}
}
}
|