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

128
Vistas
how to keep the checkbox checked using javascript

function check() {
  if (document.getElementById("myCheck").checked == true) {
    document.getElementById("myCheck").checked = true;
  }
}
<!DOCTYPE html>
<html>

<body>
  Checkbox: <input type="checkbox" id="myCheck" onclick="check()">
</body>

</html>

Description

  1. Here I have been trying to keep the check box checked if the check box is already checked.
  2. I tried to check with the status of the check box that if the checkbox is checked then setting the checked as 'true'.
  3. But it keeps unchecking the checkbox if the checkbox is checked.

What do I need

  1. I need to keep the checkbox checked if it's already checked, Please suggest only javascript.
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can remove the condition if (document.getElementById("myCheck").checked == true) if you want to keep it checked once it has been checked for the first time.

function check() {
    document.getElementById("myCheck").checked = true;
}
<!DOCTYPE html>
<html>

<body>
  Checkbox: <input type="checkbox" id="myCheck" onclick="check()">
</body>

</html>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Disable the checkbox after it has been clicked once.

document.getElementById("myCheck").disabled = true;
about 4 years ago · Juan Pablo Isaza Denunciar

0

with inputs we use onchange

const checkbox = document.getElementById('my-checkbox')
checkbox.checked = true
checkbox.onchange = function() {
    checkbox.checked = true
}
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