I am trying to check the "email" field and send the form if the "email" is not empty and valid. But for some reason the form is not sent.

var validEmail = 0; $("input[name='email']").blur(function() { if($(this).val() != '') { var pattern = /^([a-z0-9_\.-])+@[a-z0-9-]+\.([az]{2,4}\.)?[az]{2,4}$/i; if(pattern.test($(this).val())){ validEmail = 1; $(this).removeClass("error"); } else { validEmail = 0; $(this).addClass("error"); } } else { validEmail = 0; $(this).addClass("error"); } }); $("input[type='submit']").click(function(e) { e.preventDefault(); if (validEmail == 1) { $(this).parents(".order_form").submit(); } else { $(this).parents(".order_form").find("input[name='email']").addClass("error"); $(this).parents(".order_form").find("input[name='email']").focus(); } }); 

The form was found correctly, because if instead of submit () write hide () , then it is hidden.

  • And what will happen if e.preventDefault(); put in else ? - Crantisz
  • Then the form will go :-) It turns out that the abolition of the standard action happens forever? - Anton Petrenko
  • I think this may depend on the browser. - Crantisz

0