Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
reportValidity not showing message

I created a function to indicate when the input passwords do not match, but having issues with showing the built-in HTML form verification message.

When I run the debugger I do see that the custom message gets displayed, but when the function ends so those the message.

Would anyone know why the message won't persist?

function validatePassword() {
  debugger;
  let p1 = document.getElementById('password');
  let p2 = document.getElementById('confirm_password');
  p2.setCustomValidity("");

  if (p1.value != p2.value && p1.value != '' && p2.value != '') {
    p2.setCustomValidity("Passwords do not match");
    p2.reportValidity();


  }


}
<form>

  <div>
    <label for="">Password</label>
    <input type="password" id='password' onchange='validatePassword()' required>
  </div>

  <br>

  <div>
    <label for="">Confirm Password</label>
    <input type="password" id='confirm_password' onchange='validatePassword()' required>
  </div>

  <br>
  <input type="submit" value="Send">
</form>

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda