how to check confirm password field in form without reloading page

后端 未结 15 1844
青春惊慌失措
青春惊慌失措 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:17

    The code proposed by #Chandrahasa Rai works almost perfectly good, with one exception!

    When triggering function checkPass(), i changed onkeypress to onkeyup so the last key pressed can be processed too. Otherwise when You type a password, for example: "1234", when You type the last key "4", the script triggers checkPass() before processing "4", so it actually checks "123" instead of "1234". You have to give it a chance by letting key go up :) Now everything should be working fine!

    #Chandrahasa Rai, HTML code:

    
    
    
    

    #my modification:

    
    
    
    

提交回复
热议问题