Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking password match returns "Passwords match" when both fields are empty
    primarykey
    data
    text
    <p>I'm making a registration form and I want to check if the user has matching passwords while he's typing and give him the appropriate message. So far everything works, except for these things:</p> <ul> <li>When the user deletes everything from Confirm Password field it still gives him a message "Passwords do not match" while I want to give him no message or a message saying "Please confirm password".</li> <li>When the user deletes everything from both fields, it gives him a message "Passwords match", while it should give him no message at all.</li> </ul> <p>Here's my code:</p> <pre><code>$(function () { $("#txtNewPassword").keyup(checkPasswordMatch); $("#txtConfirmPassword").keyup(checkPasswordMatch); }); function checkPasswordMatch() { $("#divCheckPasswordMatch").html(""); var password = $("#txtNewPassword").val(); var confirmPassword = $("#txtConfirmPassword").val(); if (password == "" &amp;&amp; confirmPassword == ""){ $("#divCheckPasswordMatch").html(""); $("#divIsPasswordExist").html(""); } else if (password != "" &amp;&amp; confirmPassword == "") { $("#divCheckPasswordMatch").html(""); } else if (password == "" &amp;&amp; confirmPassword != "") $("#divIsPasswordExist").html("Password cannot be empty!"); else $("#divIsPasswordExist").html(""); if (password != confirmPassword) { $("#divCheckPasswordMatch").removeClass("registrationFormConfirm"); $("#divCheckPasswordMatch").addClass("registrationFormAlert"); $("#divCheckPasswordMatch").html("Passwords do not match!"); } else { $("#divCheckPasswordMatch").removeClass("registrationFormAlert"); $("#divCheckPasswordMatch").addClass("registrationFormConfirm"); $("#divCheckPasswordMatch").html("Passwords match."); } } </code></pre> <p>Any ideas, please? Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload