-4

I used jQuery and Javascript to create a script in which if two password type inputs don't match, it alerts, "password doesn't match." Here is my code:

if (!password == retypepassword) {
 document.getElementById("retypepassworderror").innerHTML = "password doesn't match";
 }
else {
$("#retypepassworderror").text("");
}

Note : both password and retypepassword are variables

4

3 回答 3

2

You are using wrong condition use this,

if (password !== retypepassword) {

in place of

if (!password == retypepassword) {

Full Code,

if (password !== retypepassword) {
    $("#retypepassworderror").text("password doesn't match");
} else {
    $("#retypepassworderror").text("");
}
于 2013-10-28T12:07:48.683 回答
0

U have to just compare two strings as below code ..

if(password == retypepassword)
{

 $("#retypepassworderror").text("");
}

else
{
    document.getElementById("retypepassworderror").innerHTML = "password doesn't match";
}
于 2013-10-28T12:10:23.227 回答
0

Are You using Asp.net web application??

If yes, u can do it using, Control Validator, which is in the toolbox, under Validation.

Add Compare Validator into your WebForm, Then in properties, change Control To Validate and Control to Compare, assign the ID's of the text boxes to each of them.

By this,You should be done, verifying if 2 strings entered into the TextBoxes are same or not.

于 2013-10-28T12:34:01.820 回答