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

127
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

Disable the checkbox after it has been clicked once.

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

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 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