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

192
Views
How to disable the button(should not do anything) if either of input is empty?

enter image description here it shows Nan when there is no number, how can a disable it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Disable the buttons in html by adding a disabled attribute. Write an on-change handler for the inputs where the buttons are enabled only if there is value.

Ref: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event

const input1 = document.querySelector('#num1');
const input2 = document.querySelector('#num2');

input1.addEventListener('change', handleButton);
input2.addEventListener('change', handleButton);

function handleButton() {
  if(input1.value && input2.value) {
    document.querySelector(".button").removeAttribute("disabled");
  } else {
    document.querySelector(".button").setAttribute("disabled", "disabled");
  }
}

You can target the buttons by the classname which you have used. I have used .button in the answer.

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!