check if a checkbox is checked with javascript

checks if the box is checked and returns true or false

reusable function that can check if a checkbox is checked or not just pass it the id of the checkbox

Javascript Usage



<input type="checkbox" id="check1"> check 1<br>
<input type="checkbox" id="check2"> check 2<br>

<button class='btn btn-primary' onclick="check_my_box('check1');">check check 1</button>
<button class='btn btn-primary' onclick="check_my_box('check2');">check check 2</button>


function check_my_box(id) {
	if (document.getElementById(id).checked) {
		alert(id + " is checked");
	} else {
    	alert(id + "# is NOT checked");
check 1
check 2

Other Items in javascript

No Items Found.

Add Comment
Type in a Nick Name here
Page Views

This page has been viewed 82 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
Most people can do absolutely awe-inspiring things,” he said. β€œSometimes they just need a little nudge.