Check password - Where is the error in code?

前端 未结 3 691
伪装坚强ぢ
伪装坚强ぢ 2021-01-28 08:06

The password authentication code, but does not work.. Where is the error in my code?

JS:

function checkPass() {
var pass = document.getE         


        
相关标签:
3条回答
  • 2021-01-28 08:10

    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).

    0 讨论(0)
  • 2021-01-28 08:16
    if(pass.value != pass2.value) {
    document.layers.passResponse.innerHTML = "Passwords did not Match!";
    } else {
    document.layers.passResponse.innerHTML = "Passwords Match!";
    }
    }
    

    Use the code above.

    0 讨论(0)
  • 2021-01-28 08:19

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

    if(pass1 != pass2) {

    Should be

    if(pass1.value != pass2.value) {
    
    0 讨论(0)
提交回复
热议问题