How to determine whether a DOJO Checkbox is checked or not?
Solution 1
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.
Solution 2
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.
Admin
Updated on June 08, 2022Comments
-
Admin almost 2 years
<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.
-
g00glen00b about 11 yearsPersonally I would use the widget code to test if a dijit checkbox is checked or not. (I'm supposing you're using the plain HTML/DOM approach). But the widget code is almost the same. (I'm not the downvoter btw).
-
Shreyos Adikari about 11 yearsYes, widget approach is the better one Dimit but more or less same.
-
g00glen00b about 11 yearsIndeed, it's just doing the same thing behind the screen. I upvoted your answer btw (to remove the negative score).