Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Conditional logic from a check box to affect a text box

New Here ,
Feb 16, 2022 Feb 16, 2022

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!

 

TOPICS
JavaScript
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Feb 16, 2022 Feb 16, 2022

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];}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 16, 2022 Feb 16, 2022

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];}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 17, 2022 Feb 17, 2022

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 17, 2022 Feb 17, 2022
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines