Reload form if I get an error when validate email

I have a form like this in an .html file:

 <body>
 <script>
      $(document).ready(function(){
         $("#submit").click(function(){
           if($("#mail").val() != $("#rmail").val()){
              alert("emails don't match");
              //?
           }
         });
      });
 </script>


<form action="action.php" method="POST">         
  <p>E-mail:</p>
    <input type = "email" id="mail" name = "correo">
  <p>Repetir e-mail:</p>
    <input type = "email" id="rmail" name = "rcorreo">
    <input id="submit" type="submit"/>
</form>
</body>

The J-Query function display an alert if the mails aren't matching and then it goes to the action.php page

What I want to do is to reload the form if the mails aren't matching and prevent getting into action.php page. I have tried location.reload(); where the //? comment but it doesn't work.

Any clue? Thanks in advance.

Upvotes: 0

Views: 41

Answers (1)

Shareef
Shareef

Reputation: 361

<body>
 <script>
      $(document).ready(function(){
         $("#submit").click(function(event){
           if($("#mail").val() != $("#rmail").val()){
              event.preventDefault();
              alert("emails don't match");
              window.location.reload();
           }
         });
      });
 </script>

I hope this would help

Upvotes: 2

Related Questions