Skip to content Skip to sidebar Skip to footer

Check Password - Where Is The Error In Code?

The password authentication code, but does not work.. Where is the error in my code? JS: function checkPass() { var pass = document.getElementById('pass'); var pass2 = document.get

Solution 1:

You are compare two html elements, not the values of them.

if(pass1 != pass2) {

Should be

if(pass1.value != pass2.value) {

Solution 2:

First, you are trying to compare two input elements, and not their values. You need to access their value properties. You should also use the strict comparison operator where possible.

if ( pass1.value !== pass2.value )

Second, you are trying to use document.layers, which is a proprietary property seen in Netscape 4.

You need a more modern guide, try the W3C's JavaScript core skils, the section on Traversing the DOM covers the area you are dealing with (but if you have been working with guides that mention layers you are likely to benefit from starting at the beginning).


Solution 3:

if(pass.value != pass2.value) {
document.layers.passResponse.innerHTML = "Passwords did not Match!";
} else {
document.layers.passResponse.innerHTML = "Passwords Match!";
}
}

Use the code above.


Post a Comment for "Check Password - Where Is The Error In Code?"