Javascript code - change text box fill

New Here ,
May 08, 2018

Copy link to clipboard

Copied

I have 2 boxes - 1) Is a running total 2) Cash Avail.  I want to write code that will change the Running Total fill to red if the amount is above the Cash Avail

Here is what I have

var RT = this.getField("Run_Total");

var CA = this.getField("CashAvail");

if(RT.value > CA.value){

event.RT.fillColor = color.red;

}else {

event.RT.fillColor = color.transparent;

}

I also tried

var RT = this.getField("Run_Total").value;

var CA = this.getField("CashAvail").value;

if(RT> CA){

event.fillColor = color.red;

}else {

event.fillColor = color.transparent;

}

But nothing happens.  I am sure I am missing something.very simple

TOPICS
Acrobat SDK and JavaScript, Windows

Views

133

Likes

Translate

Translate

Report

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

Javascript code - change text box fill

New Here ,
May 08, 2018

Copy link to clipboard

Copied

I have 2 boxes - 1) Is a running total 2) Cash Avail.  I want to write code that will change the Running Total fill to red if the amount is above the Cash Avail

Here is what I have

var RT = this.getField("Run_Total");

var CA = this.getField("CashAvail");

if(RT.value > CA.value){

event.RT.fillColor = color.red;

}else {

event.RT.fillColor = color.transparent;

}

I also tried

var RT = this.getField("Run_Total").value;

var CA = this.getField("CashAvail").value;

if(RT> CA){

event.fillColor = color.red;

}else {

event.fillColor = color.transparent;

}

But nothing happens.  I am sure I am missing something.very simple

TOPICS
Acrobat SDK and JavaScript, Windows

Views

134

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 08, 2018 0
Engaged ,
May 09, 2018

Copy link to clipboard

Copied

The second option is the good one.  You can put the script in the calculate event of "Run_Total".

var RT = event.value;

var CA = this.getField("CashAvail").value;

if(RT > CA){

event.target.fillColor = color.red;

}else {

event.target.fillColor = color.transparent;

}

Remember that if you have the option to enable the highligthing of fillable fields, they always appear blue (kind of a darkerish blue when not transparent).

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 09, 2018 0
New Here ,
May 09, 2018

Copy link to clipboard

Copied

THANK YOU MatLac!  That seemed to work.  But now when the page is blank (initial load) that field is filled red - even when I clear all fields.   Should I add something that would make is transparent on load?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 09, 2018 0
MatLac LATEST
Engaged ,
May 09, 2018

Copy link to clipboard

Copied

It should not.  Are you sur RT is empty.  Because anything, including a SPACEBAR will be evaluated as something bigger than nothing.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 09, 2018 0