Select to view content in your preferred language

ID for checkboxes

1166
3
11-08-2011 10:04 AM
SamirGambhir
Frequent Contributor
Hello,
I have a dojo 'form' element with three checkboxes (same class but unique ids). Once user makes a selection, I would like to get the id(s) and number of boxes checked. I am looking into dojo.query but having a hard time getting the results (though I could get the number of boxes that are checked). Can you please direct me to some examples where I can get clarity on this issue?
Thanks
Samir
0 Kudos
3 Replies
KellyHutchins
Esri Frequent Contributor
Do they each have an id? If so you could use dijit.byId to get the check box. Here's an example where we get value for a checkbox:


       
var bx1 = dijit.byId('checkBoxquakes');
console.log(bx1.id + " " + bx1.checked);


As you pointed out you could also use dojo.query. In this snippet we get all the checkboxes in the app then loop through and write out the id and whether or not the box is checked to the console:

   
    var boxes = dojo.query('input[type=checkbox]');
        dojo.forEach(boxes,function(box){
          console.log(box.id + " " + box.checked);
        });


Here's some more info on dojo.query:

http://dojotoolkit.org/reference-guide/dojo/query.html




      
        var boxes = dojo.query('input[type=checkbox]');
        dojo.forEach(boxes,function(box){
          console.log(box.id + " " + box.checked);
        });
0 Kudos
SamirGambhir
Frequent Contributor
Thanks Kelly for your response,
I'll definitely try out these examples. I am not sure how does console.log function? How do I retrieve the id's from the console?
Thanks
Samir
0 Kudos
KellyHutchins
Esri Frequent Contributor
Console.log writes information out to the console window. In your situation you may want to assign the id to a variable that you can then use later in your code.
0 Kudos