Copy link to clipboard
Copied
I have code that when a specific checkbox is checked, several other checkboxes become checked. I need ONLY those other checkboxes that get Checked to now be greyedout/locked checked. So the only way to uncheck them would be to deselect the original checkbox. The code is below.....
var otherCheckBoxes = ["Local Travel", "Taxi", "Public Transit", "Province", "Region", "Private Motor Vehicle", "Government Fleet vehicle", "Air1", "Rail1", "Bus1", "Ferry1", "Taxi3", "Rental Motor Vehicle1", "Public Transit1", "Private Motor Vehicle2", "Government Fleet vehicle2", "Air", "Rail", "Bus", "Ferry", "Taxi2", "Rental Motor Vehicle", "Public Transit2", "Private Motor Vehicle1", "Government Fleet vehicle1"]; // etc.
if (getField("Canada").value!="Off") {
for (var i in otherCheckBoxes) getField(otherCheckBoxes).checkThisBox(0,true);
}
else if (getField("Canada").value!="On") {
for (var i in otherCheckBoxes) getField(otherCheckBoxes).checkThisBox(0,false);
}
Change the last part of the code to:
if (this.getField("Canada").value!="Off") {
for (var i in otherCheckBoxes) {
this.getField(otherCheckBoxes).checkThisBox(0,true);
this.getField(otherCheckBoxes).readonly = true;
}
} else if (this.getField("Canada").value!="On") {
for (var i in otherCheckBoxes) {
this.getField(otherCheckBoxes).checkThisBox(0,false);
this.getField(otherCheckBoxes).readonly = false;
}
}
Copy link to clipboard
Copied
Change the last part of the code to:
if (this.getField("Canada").value!="Off") {
for (var i in otherCheckBoxes) {
this.getField(otherCheckBoxes).checkThisBox(0,true);
this.getField(otherCheckBoxes).readonly = true;
}
} else if (this.getField("Canada").value!="On") {
for (var i in otherCheckBoxes) {
this.getField(otherCheckBoxes).checkThisBox(0,false);
this.getField(otherCheckBoxes).readonly = false;
}
}
Copy link to clipboard
Copied
By the way, your code is a bit confusing. Why use the NOT-EQUALS operator instead of the EQUALS one? It would make it more readable.
It can even be simplified even more, to:
var isCanada = (this.getField("Canada").value!="Off");
for (var i in otherCheckBoxes) {
this.getField(otherCheckBoxes).checkThisBox(0, isCanada);
this.getField(otherCheckBoxes).readonly = isCanada;
}