Joe Shamuraq
Joe Shamuraq

Reputation: 1385

Validating 2 email address inout by users

I am very new in Ajax and need to come up with a self validating registration form using Ajax. I am comparing 2 email address textfield as such:

$("#email2").change(function() 
      { //if theres a change in the email textbox
        var email1 = $("#email1").val();//Get the value in the email textbox
        var email2 = $("#email2").val();
        $("#email_format2").html('<img src="loader.gif" align="absmiddle">&nbsp;Checking format');
          //Add a loading image in the span id="availability_status"
         if(email1 != $email2){
            $("#email_format2").html('<img src="not_available.png" align="absmiddle"> <font color="red">Email does not match </font>')
        }
        else{
            $("#email_format2").html('<img src="available.png" align="absmiddle"> <font color="Green"> Email match </font>  ');
        }
      return false;
      });

Is there anything wrong with the code above as nothing happens except for the loader.gif spinning around waiting for something to happen.

Upvotes: 0

Views: 51

Answers (2)

Tapas Pal
Tapas Pal

Reputation: 7207

Just remove the $ sign before email2 and try again...

if(email1 != $email2)

Upvotes: 1

chandresh_cool
chandresh_cool

Reputation: 11830

Please check your code

if(email1 != $email2)

$email2 is not correct way to go with

it should be

if(email1!=email2)

Upvotes: 1

Related Questions