Copy link to clipboard
Copied
Hi,
I'm trying to create a document where if a check box is checked/active, the fill color of a corresponding text box changes to red and the border color changes. If the check box is not checked/inactive, the fill color and border of the text box is transparent. By default, the text box has transparent fill and border color. I have no experience with Javascript but have familiarity with Excel and VBA.
Check box name: One Time Address check box
Text box name: OneTimeAddr
Here's what I have so far from googling things:
var cOneTime = this.getField("One Time Address check box").isBoxChecked(1);
var fld = this.getField("OneTimeAddr");
fld.strokeColor = ["RGB",0,0,1];
fld.fillColor = ["RGB",1,0,0];
fld.textColor = ["RGB",0,0,0];
What would be an appropriate trigger? I'm using On Focus for the above script.
Thank you!
Copy link to clipboard
Copied
You are on the right track, use script as 'Mouse UP', in 'isBoxChecked(1)' change 1 to 0, and wrap lines with colors in curly brackets also you are missing condition and 'else' condition to set colors when checkbox is unchecked, something like this:
var cOneTime = this.getField("One Time Address check box").isBoxChecked(0);
var fld = this.getField("OneTimeAddr");
if(cOneTime){
fld.strokeColor = ["RGB",0,0,1];
fld.fillColor = ["RGB",1,0,0];
fld.textColor = ["RGB",0,0,0];}
else{
fld.strokeColor = color.transparent;
fld.fillColor = color.transparent;
fld.textColor = ["RGB",0,0,0];}
Copy link to clipboard
Copied
You are on the right track, use script as 'Mouse UP', in 'isBoxChecked(1)' change 1 to 0, and wrap lines with colors in curly brackets also you are missing condition and 'else' condition to set colors when checkbox is unchecked, something like this:
var cOneTime = this.getField("One Time Address check box").isBoxChecked(0);
var fld = this.getField("OneTimeAddr");
if(cOneTime){
fld.strokeColor = ["RGB",0,0,1];
fld.fillColor = ["RGB",1,0,0];
fld.textColor = ["RGB",0,0,0];}
else{
fld.strokeColor = color.transparent;
fld.fillColor = color.transparent;
fld.textColor = ["RGB",0,0,0];}
Copy link to clipboard
Copied
Thank you for the reply! This works nearly perfectly. I'm not sure if I'm missing something or misspoke but the fill color for the text box only changes when the check box is active AND the text box is selected/in focus. Would you know how I could adjust the code so that when the check box is active, the text box fill color changes even when it's not in focus/selected? Appreciate your time and effort!
Copy link to clipboard
Copied
I was definitely missing something here, the SELECTABLE text field highlight made it seem like the fill color didn't change but it actually does. Appreciate your quick and excellent response!
Take care, stay safe

