Not a Member Yet,
Click here to Register
How do you like the new design?






ID: 61
Viewed: 2564
Added: Jan 24, 2002
Version:
Snippet uploaded by: Jon Hanlon
Written By: Jon Hanlon
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

This routine will return the checked value of a Radio Button, or set it for you.

<!---Head--->

function getSetRadio(obj) { // P2 is optional and implies we are Setting
for (var i=0; i < obj.length; i++) {
if (arguments.length > 1) { // we are setting
if (arguments[1] == null) {
obj[i].checked = false;
} else
if (obj[i].value == arguments[1]) {
obj[i].checked = true;
return true;
}
} else { // we are getting
if (obj[i].checked) return obj[i].value;
}
}
return false;
}

<!---Body--->


 
<form name="myForm">
<input type=radio name="gender" value="Boy">Male<br>
<input type=radio name="gender" value="Girl">Female<br>
</form>


var sex = getSetRadio(myForm.gender) // returns "Boy", "Girl", or false
getSetRadio(myForm.gender,"Boy") // selects Male
getSetRadio(myForm.gender,null) // unselects all.


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 snippetlibrary.com All Rights Reserved. Conditions