jquery - When form is submitted, validate html checkbox and display javascript alert if it is not checked -


i'm trying validate form in html using jquery , possibly jquery validation plugin. want happen when submit button pressed, should validate whether html checkbox checked or not. if not checked, want give out javascript alert error saying not checked. otherwise form should submit normally. i'm trying integrate wordpress form created using contact form 7 plugin.

i have added code per request.

<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>      <script src="http://malsup.github.com/jquery.form.js"></script>       <script>          // wait dom loaded          $(document).ready(function() {              // bind 'myform' , provide simple callback function              $('#myform').ajaxform(function() {                  alert("thank comment!");              });          });      </script>  </head> <body> <form id="myform" action="action.php" method="post">  <input type="checkbox" name="tos" value="agreed tos" id="confirm"> <input type="submit" value="submit comment" />  </form> </body> </html> 

don't have much, yet , trying use jquery validate. might simple using javascript.

if

<input id="submit" type ="submit" name ="submit" /> 

is submit button in form, add onclick it.

<input id="submit" type ="submit" name ="submit" onclick = "return validate();"> 

your validate should like:

function validate(){   if checkbox set        return true;   else        return false; } 

if validate function returns true, form submitted.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -