0

This is my form

   Select Staff : <select name="Staff" id="Staff"><br />
   <option value="Staff">Select Staff</option>

The validation for the form is as simple this

<script type="text/javascript" language="javascript"> 
function validateMyForm ( ) { 
    var isValid = true;
    if ( document.form1.Name.value == "" ) { 
        alert ( "Please type your Name" ); 
        isValid = false;
    }  else if ( document.form1.Staff.value == "Staff" ) { 
            alert ( "Please choose Staff" ); 
            isValid = false;
    } 
    return isValid;
}
</script>

How do I validate radio buttons using JS ?

Wilfred Clement
  • 2,674
  • 2
  • 14
  • 29

1 Answers1

2
<input type="radio" name="question" id="question_yes" value="Yes" />Yes<br>
<input type="radio" name="question" id="question_no" value="No" />No

<script>
if(document.getElementById('question_yes').checked) {
  // yes is checked
}else if(document.getElementById('question_no').checked) {
  // no is checked
}
</script>

Here's a jsFiddle to show you how it works: http://jsfiddle.net/A3fg8/

Gavin
  • 7,544
  • 4
  • 52
  • 72