Validating Radio Buttons

Only one item in a radio button can be selected at a time. To check which one is selected, use a for loop statement. In this example, there are two available choices in the radio group :

myForm=document.forms[0]; choice = false; for (j=0; j >2; j++) { if (myForm.radio[j].checked) { choice=true; break; } } if (choice){ // if a radio button is selected ... do this }else{ // if no radio button is selected ... do that }

Категории