title: Password and confirm password validation in javascript error?
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var password = document.getElementById("password");
  var confirm_password = document.getElementById("confirm_password");
  
  function validatePassword()
  {
    if(password.value != confirm_password.value)
    {
      confirm_password.setCustomValidity("Passwords Don't Match");
    } 
    else if(password.value=='')
    {
      password.setCustomValidity("Passwords must not be empty");
    } 
    else
    {
      password.setCustomValidity('');
    }
  }
  password.onchange = validatePassword;
  confirm_password.onkeyup = validatePassword;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="password" name="password" id="password" placeholder="Please Enter Password" required="required"/&gt;
  &lt;input type="password" name="confirm_password" id="confirm_password" placeholder="Confirm Password"  required="required"/&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I need to show password empty message while submitting without typing anything.<br>
  It validates mismatching but it is not validating empty fields. Any solution?</p>