Reputation:
<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.
Upvotes: 5
Views: 11165
Reputation: 44665
You 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.
Upvotes: 13
Reputation: 12744
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.
Upvotes: 6