Help with "For" Loop... Not Checking All Boxes in Array
Hi there! I am having trouble with a script I'm working on and hoping I can get some advice.
I have a form with several fields that are either visible or hidden depending on the state chosen by the user. The user may select different state forms by checking check boxes, then hits a button to append those state forms to the document.
When a user selects their state, a function runs to set their location (this consists of making state specific fields visible, and checking all boxes for each state form by default). The checkbox portion is where I'm running into issues. My loop will only check or uncheck the first box, then stop. Here is the portion of code in question:
var Location = this.getField("LOCATION").value;
var ME1 = this.getField("ME_1");
var ME2 = this.getField("ME_2");
var ME3 = this.getField("ME_3");
var ME4 = this.getField("ME_4");
var ME5 = this.getField("ME_5");
var NH1 = this.getField("NH_1");
var VT1 = this.getField("VT_1");
var VT2 = this.getField("VT_2");
var allChecks = [ME1, ME2, ME3, ME4, ME5, NH1, VT1, VT2];
var StateChecks = [];
//Loop through fields and push to new array depending on state chosen
for (i = 0; i < allChecks.length; i++) {
if (Location == "KPOR" || Location == "KBAN") {
if (allChecks.name.indexOf("ME") !== -1) {
StateChecks.push(allChecks);
}
}
}
for (i=0; i < allChecks.length; i++) {
allChecks.checkThisBox(0,false);
}
for (i=0; i < StateChecks.length; i++) {
StateChecks.checkThisBox(0,true);
}
}
In testing snippets of this code in another document, I was able to get the following to work properly and check all three boxes.
var ME1 = this.getField("ME_1");
var ME2 = this.getField("ME_2");
var ME3 = this.getField("ME_3");
var allChecks = [ME1, ME2, ME3];
for (i=0; i < allChecks.length; i++) {
allChecks.checkThisBox(0,true);
}
However, even testing just that small snippet in the current form I'm working on, it still only checks one of the boxes.
Any advice would be greatly appreciated ![]()
