I have a form
<form method="post" action="sendmail.php" name="Email form">
Message ID
<input type="text" name="message_id" /><br/><br/>
Aggressive conduct
<input type="radio" name="conduct" value="aggressive contact" /><br/><br/>
Offensive conduct
<input type="radio" name="conduct" value="offensive conduct" /><br/><br/>
Rasical conduct
<input type="radio" name="conduct" value="Rasical conduct" /><br/><br/>
Intimidating conduct
<input type="radio" name="conduct" value="intimidating conduct" /><br/><br/>
<input type="submit" name="submit" value="Send Mail" />
</form>
I need some sort of validation javascript that:
- Checks if user entered a message id and checked one of the radio buttons. (So message id and radio group are required fields)
- Display an error message if any of the required fields is not set.
- Block form submit until required fields are entered.
Can anyone help?
You will have to do a validation before submit.
Add an on submit event handler (that will be called when the form is submitted) to the form:
You can do this in two ways:
OR
in the
<script>part:Now write the validate function itself (same for both options above):