The password authentication code, but does not work.. Where is the error in my code?
JS:
function checkPass() {
var pass = document.getE
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).
if(pass.value != pass2.value) {
document.layers.passResponse.innerHTML = "Passwords did not Match!";
} else {
document.layers.passResponse.innerHTML = "Passwords Match!";
}
}
Use the code above.
You are compare two html elements, not the values of them.
if(pass1 != pass2) {
Should be
if(pass1.value != pass2.value) {