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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.