validation using javascript for radio button in asp

how can i validate using javascript for radio button in asp?
Who is Participating?
thiyagukTech Lead Commented:
<form name="myform">
<input type="radio" value="1st value" name="myradiobutton" />1st<br />
<input type="radio" value="2nd value" name="myradiobutton" />2nd<br />
<input type="radio" value="3rd value" name="myradiobutton" />3rd<br />&nbsp;<br />
<input type="submit" name="submitit" onclick="valbutton(myform);return false;" value="Validate" />
<input type="reset" name="reset" value="Clear" />

The javascript that this form uses to validate that a radio button has been selected follows. An alert advising that you must select a button will display if no button is selected. When a button is selected, the value of the myOption field will contain the number of the button selected. Note that the buttons are numbered starting from zero. In this instance for the purpose of illustration, we simply display an alert advising which button was selected (shown in italics).

function valbutton(thisform) {
// place any other field validations that you require here
// validate myradiobuttons
myOption = -1;
for (i=thisform.myradiobutton.length-1; i > -1; i--) {
if (thisform.myradiobutton[i].checked) {
myOption = i; i = -1;
if (myOption == -1) {
alert("You must select a radio button");
return false;
System_ExpertAuthor Commented:
fine code
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.