Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Finding and unchecking all checkboxes

Level 1
Level 1

I have a form that has a radio set of options. Based on what you select, a table of different checkboxes appears. Because you're only supposed to be able to select one of the option sets, and because when you export the form to XML, it exports *all* the data, even if you checked options in multiple sets and hid them later, I want a script that goes through and unchecks *all* checkboxes. I'm struggling.

The hierarchy is as follows:

- Subform: Causes (a radio set, so you can only select one)
- Subform: Subcauses (the different option sets live here)
   - Subform: Subcause 1
       - Table of checkboxes
   - Subform: Subcause 2
   - etc.

So when the user clicks on one of the radio buttons in the "Causes" subform, the script needs to start at the "Subcauses" subform and traverse all containers under it looking for checkboxes. If it finds one, it should uncheck it. Here's what I have now. It's being invoked properly, but the inner loop isn't finding checkboxes. Any help greatly appreciated!!

function traverse(oParentNode) {
      var allChildElements;
      var intNumElements;
      var currentElement;
      var i;
      var j;
            // Get all occurances of the parent element
      intNumOccurances = oParentNode.all.length;
            for (i=0; i < intNumOccurances; i++)      {
           oCurrentParent = oParentNode.all.item(i);
                      // Get all the child nodes of the parent element
           allChildElements = oCurrentParent.nodes;
                      // Total number of elements in the object
           intNumElements = allChildElements.length;
                      // Loop through all the child elements
           for (j=0; j < intNumElements; j++)
                currentElement = allChildElements.item(j);
                                //If it's a field, process
                if (currentElement.className == "field")
                     if (currentElement.isPropertySpecified("ui") && currentElement.ui.nodes.item(0).className == "checkButton")
                          currentElement.rawValue = 0;
                //Otherwise recurse
0 Replies