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

check_my_box('check1');

HTML

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

Javascript

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 86 times.

Search Code
Search Code by entering your search text above.
Welcome

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
time you enjoyed wasting is not wasted time
Unknown