Jump to content

[SOLVED] Need help with JQuery checking if 2 fields are same value.


Flames

Recommended Posts

Earlier today I decided to use JQuery to help with Ajax, and I started using certain styles so I decided I'd change all my validation to work with JQuery.

This is part of my JS to validate of 2 username fields are the same

 

$("#user2").blur(function()
{
$("#msgbox_check").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
if($(this).value == $("#user").value)
{
   $("#msgbox_check").fadeTo(200,0.1,function() //start fading the messagebox
   {
    //add message and change the class of the box and start fading
    $(this).html('Inputted Username\'s match').addClass('messageboxok').fadeTo(900,1);
   });
}
else
{
   $("#msgbox_check").fadeTo(200,0.1,function() //start fading the messagebox
   {
    //add message and change the class of the box and start fading
    $(this).html('Inputted Username\'s do not match').addClass('messageboxerror').fadeTo(900,1);
   });
}
});

 

And this is the code of the 2 fields (ignore the \'s its because it is PHP not HTML)

 

<tr><td>Username</td><td><input type=\"text\" name=\"user\" id=\"user\" > <span id=\"msgbox\" style=\"display:none\"></span></td></tr>
<tr><td>Repeat Username</td><td><input type=\"text\" name=\"user2\" id=\"user2\"> <span id=\"msgbox_check\"  style=\"display:none\"></span></td></tr>

 

Problem is the code always says that the 2 values are the same.

Any help please?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.