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.
Solution Using jQuery
And update your form accordingly:
This will do precisely what you asked for:
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.