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 ?

2

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.