0
$("#Month option:selected").val();

By this we can get the selected value in our DDL. same as this how can we get weather CheckBox is checked or not. How can i do this?

<input id="Baruc" type="checkbox" value="true" name="Baruc" data-val-required="The Baruc field is required." data-val="true" onchange="showlabel();">

for this checkbox?

Sachin Yadav
  • 187
  • 3
  • 4
  • 15
  • possible duplicate of [Check checkbox checked property](http://stackoverflow.com/questions/901712/check-checkbox-checked-property) – Adrian Wragg Feb 24 '15 at 11:12

5 Answers5

0

In order to check whether a checkbox is checked or not you can try using .is() as shown :-

jQuery syntax.

$('#Baruc').is(':checked') // it returns bool if checkbox is checked it will return 'true' otherwise 'false'.

Edit :- there must be a colon before checked

Javascipt syntax.

if(document.getElementById("Baruc").checked)
{
   //checkbox is checked
}
Sachin Yadav
  • 187
  • 3
  • 4
  • 15
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69
0

Solution 1:

You need to use .length for checked elements.

if($("#Baruc:checked").length){
  //checkbox is checked
}

Solution 2:

also you can use .is() method with :checked selector:

if($("#Baruc").is(":checked")){
  //checkbox is checked
}
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

Use this

$('#Baruc').is('checked');
I'm Geeker
  • 4,601
  • 5
  • 22
  • 41
0

you can pass this in your onchange function:

onchange="showlabel(this);

now in your method you can use this:

function showlabel(elem){
    alert(elem.checked); // true if checked false if unchecked
}

function showlabel(elem){ alert(elem.checked);}
<input id="Baruc" type="checkbox" value="true" name="Baruc" data-val-required="The Baruc field is required." data-val="true" onchange="showlabel(this);">
Jai
  • 74,255
  • 12
  • 74
  • 103
0

You can check if the checkbox is checked or not by the given code :

$(‘#CHECKBOXID’).is(‘:checked’);

if any confusions then use the below link :

https://codeupweb.wordpress.com/2017/07/11/check-if-checkbox-if-checked-using-jquery/

Akshit Ahuja
  • 337
  • 2
  • 15