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

209
Visualizações
Enable/Disable button based on password input length with Javascript

Trying to enable/disable a form button based on password input length but my code doesn't work. If the length is less than 15 characters button should be disabled.

So far my simple html form

<form class="form" id="form1" method="POST" action="submit.php" accept-charset="UTF-8" autocomplete="off">
   <input type="password" placeholder="Password" id="passfield">
   <button type="submit" id="form-submit">CONNECT</button>
</form>

No username field needed in my case

and so far my Javascript code

function submit_btn() {

  var field = document.getElementById("passfield");
  var button = document.getElementById("form-submit");

  if (field.value.lenght < 15){
    button.setAttribute("disabled", "");
  }else{
    button.removeAttribute("disabled");
  }
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Where do you call submit_btn?

Also spelling length

Here is a better version

const field = document.getElementById("passfield");
const button = document.getElementById("form-submit");

field.addEventListener("input", function() {
  button.disabled = field.value.length < 15;
})
<form class="form" id="form1" method="POST" action="submit.php" accept-charset="UTF-8" autocomplete="off">
  <input type="password" placeholder="Password" id="passfield">
  <button type="submit" disabled id="form-submit">CONNECT</button>
</form>

about 4 years ago · Juan Pablo Isaza Relatório
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