Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda