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

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

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 Report

0

Disable the checkbox after it has been clicked once.

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

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