Skip to content

JavaScript set checkbox checked | Check/Uncheck checkbox Example code

  • by

How to Check/Uncheck checkbox with JavaScript?

Use the GetElementById property and assign the checked is true for Check or false for Uncheck checkbox in JavaScript. You can easily modify it based on your conditions and requirements.

document.getElementById("checkBoxID").checked = true;
document.getElementById("checkBoxID").checked = false;

Example of JavaScript set checkbox checked

Here is HTML example code.

<!DOCTYPE html>


        <input id="checkbox1" type="checkbox" checked="" name="copy1">Check</input>
        <input id="checkbox2" type="checkbox" checked="true" name="copy1" value="Auto UnCheck">UnCheck</input>
    <script language="javascript">
        document.getElementById("checkbox1").checked = true;
        document.getElementById("checkbox2").checked = false;



Example of JavaScript set checkbox checked

Do comment if you have questions or doubts on this topic. You can also give suggestions and example.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.