Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!