<input id="test" type="checkbox" value="test" data-dojo-type="dijit.form.CheckBox">
How to check above dojo checkbox is checked or not in my javaScript function.
<input id="test" type="checkbox" value="test" data-dojo-type="dijit.form.CheckBox">
How to check above dojo checkbox is checked or not in my javaScript function.
Share Improve this question edited Jun 19, 2013 at 3:54 Shreyos Adikari 12.7k19 gold badges75 silver badges82 bronze badges asked Apr 5, 2013 at 9:42 user1727939user17279392 Answers
Reset to default 13You can check this in various ways. You can use plain HTML/DOM/JavaScript and use something like:
if (document.getElementById("test").checked) { ... }
or with Dojo:
if (dojo.byId("test").checked) { ... }
This is what @Shreyos Adikari meant I think but you can also use the widget itself (which is doing the same thing behind the screens) with:
if (dijit.byId("test").checked) { ... }
The difference between the first two methods and the last one, is that the first two use DOM nodes, while the last one uses the Dojo CheckBox widget/object which has a similar property. I personally recommend the last one, because this should always work, even if they decide to change their template.
But anyhow, there are plenty of examples on the web about how to achieve this (even on the Dojo documentation itself), I recommend you to view the API Documentation or at least the examples.
You can use javascript function checked over id, like:
if (test.checked == 1){
alert("checked") ;
}
else{
alert("unchecked") ;
}
Here .checked will return "1" in case the checkbox is checked.
Please try this in your javascript and let me know in case of any concern.