Copy link to clipboard
Copied
Hello,
I have 20 fields (check boxes) that can be hidden/visible based upon the value of a textfield (Counter). My script works fine, but, it's really long (161 lines) and there is a slight lag when I press a button that changes the value of the counter. My script is a caculation script attached to a hidden textfield. Is there a better way to write this script? Here is what I have:
var c = this.getField("Counter");
var b1 = this.getField("Blah 1");
var b2 = this.getField("Blah 2");
var b3 = this.getField("Blah 3");
// etc etc. down to 20
if(c.value == "1"){
b1.display = display.visible;
}
else {
b1.display = display.hidden;
}
if(c.value == "2"){
b2.display = display.visible;
}
else {
b2.display = display.hidden;
// etc etc. down to 20
You can use this as custom calculation script of "Counter" field:
for(var i=1; i<=20; i++){
if(event.value == i)
this.getField("Blah "+i).display = display.visible;
else
this.getField("Blah "+i).display = display.hidden;}
Copy link to clipboard
Copied
You can build the field name. E.g.:
this.getField("Blah " + c.value)
Copy link to clipboard
Copied
So basically delete variables b1-20?
And change all b1.display = display.visible;
to this? this.getField("Blah " + c.value).display = display.visible;
Copy link to clipboard
Copied
You can use this as custom calculation script of "Counter" field:
for(var i=1; i<=20; i++){
if(event.value == i)
this.getField("Blah "+i).display = display.visible;
else
this.getField("Blah "+i).display = display.hidden;}
Copy link to clipboard
Copied
Thank you so much, this is perfect.