user1727939
user1727939

Reputation:

How to determine whether a DOJO Checkbox is checked or not?

<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

Answers (2)

Dimitri Mestdagh
Dimitri Mestdagh

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

Shreyos Adikari
Shreyos Adikari

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

Related Questions