0
Q:

javascript checkbox checked

//using plane javascript 
if(document.getElementById('on_or_off_checkbox').checked) {
    //I am checked
} 

//using jQuery
if($('#on_or_off_checkbox').is(':checked')){
    //I am checked
}
21
if(document.getElementById('on_or_off_checkbox').checked) {
    //I am checked
}else{
	//I am not checked
}
11
document.getElementById("checkbox").checked;
6
/*Have a HTML checkbox set to any Id of your choice-Example:
<input type="checkbox" id="test">
Also make it send for a function using onclick="testfunction()"
You can use any name for the function.*/
function testfunction() {
             var x = document.getElementById("test").checked;
             document.getElementById("text").innerHTML = x;
                }
/*Line 6 is testing a checkbox with an Id of "test" to see if
it's checked, it will send either a "true" or "false" output.
Line 7 is taking a text element from HTML with an Id of "text",
it takes that text and sets it to the variable "x". Since "x"
is set to "true" for the example, it will turn any text element
with the Id to say "true".*/
2
<input type="checkbox" onchange="doSomething(this)">

function doSomething(element){
   var isChecked=element.checked;
	//do some action if it is checked
}
2
if (document.getElementById('id of the check box here').checked) {
	// it is checked. Do something
} else {
	// it isn't checked. Do something else
}

if ($('input[name="transport"]').is(':checked')) {
	alert('checked');
	alert($(this).attr('id')); //To get ID of checkBox
}
-1

        
            
        
     const cb = document.getElementById('accept');
console.log(cb.checked);
1
<script type=text/javascript>
  function validate(){
    if (remember.checked == 1){
      alert("checked") ;
    } else {
      alert("You didn't check it! Let me check it for you.")
    }
  }
</script>

<input id="remember" name="remember" type="checkbox" onclick="validate()" />
0

New to Communities?

Join the community