I am trying to access some diji.form.checkBoxes from javascript to find that checkboxes that have been checked by a user. My code is below. If I was using straight javascript I would use getElementsByName and do a for loop looking for the checked checkboxes. However, I need to do this with dojo and am unusure how to retreive the checked checkboxes. Any help would be appreciated
<tr>
<td colspan= "2">
<!-- <input type="checkbox" name="fields" value="InstitutionName" /> College Name -->
<input dojotype="dijit.form.CheckBox" name="fields" value="Address"; onKeyUp="dojoFunction();" /> Address
<input dojotype="dijit.form.CheckBox" name="fields" value="City"; onKeyUp="dojoFunction();" /> City
<input dojotype="dijit.form.CheckBox" name="fields" value="Zip"; onKeyUp="dojoFunction();" /> Zipcode
<input dojotype="dijit.form.CheckBox" name="fields" value="Phone"; onKeyUp="dojoFunction();" /> Phone Number
</td>
</tr>
<tr>
<td colspan= "2">
<input dojotype="dijit.form.CheckBox" name="fields" value="GeneralURL"; onKeyUp="dojoFunction();" /> General URL
<input dojotype="dijit.form.CheckBox" name="fields" value="AdmissionsURL"; onKeyUp="dojoFunction();" /> Admissions URL
<input dojotype="dijit.form.CheckBox" name="fields" value="FederalAidURL"; onKeyUp="dojoFunction();" /> Financial AId URL
<input dojotype="dijit.form.CheckBox" name="fields" value="ApplicationsURL"; onKeyUp="dojoFunction();" /> Application URL
</td>
</tr>
http://jsfiddle.net/yw4pza8p/
First, it's recommended to use data-dojo-type instead of the deprecated dojotype.
To get the checkboxes, we can simply query by a CSS selector:
We can loop over this array to determine if a checkbox is checked. The simplest way to do this is
OR if you want to get the actual widget, it's like this:
If all you need is the former, go with that. But if you need more functionality, like an onChange event listener, use the widget.