how to check confirm password field in form without reloading page

后端 未结 15 1808
青春惊慌失措
青春惊慌失措 2020-12-12 13:58

I have a project in which I have to add a registration form and I want to to validate that the password and confirm fields are equal without clicking the register button.

15条回答
  •  执念已碎
    2020-12-12 14:35

    You can check confirm password by only simple javascript

    html

    
    
    

    and in javascript

       function register() {
    
        var password= document.getElementById('password').value ;
        var confirm= document.getElementById('confirmpassword').value;
    
        if (confirm!=password){
          var field = document.getElementById("checkconfirm")
          field.innerHTML = "not match";
        }
      }
    

    Also you can use onkeyup instead of onkeypress.

提交回复
热议问题