how to check confirm password field in form without reloading page

后端 未结 15 1850
青春惊慌失措
青春惊慌失措 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 14:17

    Solution Using jQuery

     
    
     
    
     
    

    And update your form accordingly:




    This will do precisely what you asked for:

    • validate that the password and confirm fields are equal without clicking the register button
    • If password and confirm password field will not match it will place an error message at the side of confirm password field and disable registration button

    It is advisable not to use a keyup event listener for every keypress because really you only need to evaluate it when the user is done entering information. If someone types quickly on a slow machine, they may perceive lag as each keystroke will kick off the function.

    Also, in your form you are using labels wrong. The label element has a "for" attribute which should correspond with the id of the form element. This is so that when visually impaired people use a screen reader to call out the form field, it will know text belongs to which field.

提交回复
热议问题