0

What code will I put if I want to delay the sending of the form in my email if the email that the user have input didn't match in the confirm email?

<p class="s5">
    <span>Email:<span class="s6">*</span></span>
    <span style="margin-left: 295px;">Please enter your email address again: <span class="s6">*</span></span><br>
    <input type="text" id="input12" name="email" style="width: 275px;" required/>
    <input type="text" id="input13" name="email2" style="margin-left: 38px; width: 305px;" required/><br>
    <span class="s13">Email doesn't match!</span>
</p>

jq

$("#myform").on('submit', function(e) {
    var email = $("#input12").val(),
        confirm = $("#input13").val();

    if (email!=confirm) {
       $(".s13").show();
       $("#input13").focus();
    }
});

p.s. is the code that I show enough or do I still need to include the php file?

  • I suggest you add a PHP method as a "Plan B" (since you did tag as PHP), should the user disable JS, rendering this *useless*. You do have a "Plan B", *right?* – Funk Forty Niner Jan 30 '15 at 01:50

2 Answers2

0

You can stop the form from being submitted by adding a return false:

if (email!=confirm) {
   $(".s13").show();
   $("#input13").focus();
   return false;
}
j08691
  • 204,283
  • 31
  • 260
  • 272
0

Believe you need a preventDefault to stop the submission, like this:

$("#myform").on('submit', function(event) {
    var email = $("#input12").val(),
        confirm = $("#input13").val();

    if (email!=confirm) {
       $(".s13").show();
       $("#input13").focus();

       if(event.preventDefault)
          event.preventDefault();
       else
          event.returnValue = false;
    }
});
Chris du Preez
  • 539
  • 3
  • 8