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

<body>

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


</body>
</html>

Output:

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

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading