samirgambhir

Check all check boxes in a group programatically

Discussion created by samirgambhir on Jun 18, 2012
Hi,
I am trying to implement this function where a toggle button would check all check boxes within a group but it is not working. My HTML document:
<div dojoType="dijit.TitlePane" id="group1A" title="Population projection" open="false">
            <table id="popIndTableA">
              <tr>
                <td id="indCBRA">Crude Birth Rate</td>
                <td><input data-dojo-type="dijit.form.CheckBox" class="check1A" id="checkCBRA" name="checkCBRA" /></td>
                <td id="infoCBRA"><img id="imgCBRA" src="Images/help.png"  width="16px" onClick="" /></td>
              </tr>
              <tr>
                <td id="indTestA1">Test 1</td>
                <td><input data-dojo-type="dijit.form.CheckBox" class="check1A" id="checkTestA1" name="checkTestA1" /></td>
                <td id="infoTestA1"><img id="imgTestA1" src="Images/help.png"  width="16px" onClick="" /></td>
              </tr>
              <tr>
                <td id="indTestA2">Test 2</td>               
                <td><input data-dojo-type="dijit.form.CheckBox" class="check1A" id="checkTestA2" name="checkTestA2" /></td>
                <td id="infoTestA2"><img id="imgTestA2" src="Images/help.png"  width="16px" onClick="" /></td>
              </tr>
            </table>
            <!--br />
            <button data-dojo-type="dijit.form.Button" data-dojo-id="check1A">Select all</button-->
          </div>
          <div dojo-data-type="dijit.form.Form" id="selectGrp1A" name="selectGrp1A">
            <button dojoType="dijit.form.ToggleButton" iconClass="dijitCheckBoxIcon" id="selGrp1A" onclick="selRemChecks('group1A',1,this.id); ">Select group </button>
          </div>

My JavaScript code:
function selRemChecks(aDivId,i,buttonId){
        var k=i-1;
        var myDiv = dijit.byId(aDivId);
        var className = 'check'+i+'A';
        var myInputs = document.getElementsByTagName('input');
        if (checkActive[k]==false){
          for (j=0;j<myInputs.length; j++){
            if(myInputs.class==className){
              myInputs[j].checked=true;
            }
          }
        dijit.byId(buttonId).set("label", "Clear group");
        checkActive[k]=true;
        }
        else if (checkActive[k]==true){
          for (j=0;j<myInputs.length; j++){
            if(myInputs[j].class==className){
              myInputs[j].checked=false;
            }
          }
        dijit.byId(buttonId).set("label", "Select group");
        checkActive[k]=false;
        }
      }

Please let me know how can I make it work.
Thanks
Samir

Outcomes