Skip to main content
Participating Frequently
July 19, 2019
Question

Check box runs a script in another field

  • July 19, 2019
  • 2 replies
  • 1870 views

First off let me begin by saying I am a newbie at JAVA. I have some DBase knowledge from years ago so somethings in JAVA are not foreign to me. My question is... I have a pdf form where i want to runs a calculation script based on a check box. So, I check a box and it runs a script in another field name. I have been searching the web and found some similar scripts but they don't do what I want. Thanks in advance for your help.

This one works filling in the value in the same field

var nFOOTAGE = this.getField("FOOTAGE").value;

if(( nFOOTAGE >= 1 ) && ( nFOOTAGE <= 1500 ))event.value = 250;

else if(( nFOOTAGE >= 1501 ) && ( nFOOTAGE <= 2000 )) event.value = 300;

else if(( nFOOTAGE >= 2001 ) && ( nFOOTAGE <= 2500 ))event.value = 325;

else if(( nFOOTAGE >= 2501 ) && ( nFOOTAGE <= 3000 ))event.value = 350;

else if(( nFOOTAGE >= 3001 ) && ( nFOOTAGE <= 3500 ))event.value = 375;

else if(( nFOOTAGE >= 3501 ) && ( nFOOTAGE <= 4000 ))event.value = 400;

else event.value = 0;

but I want a checkbox (RICheckBox) to activate the above formula in another field (RIP).

I tried this but keep getting an error message at line 2

if (this.getField("RIPCheckbox").value=="Off") event.value = "";

else event.value= var nFOOTAGE = this.getField("FOOTAGE").value;

if(( nFOOTAGE >= 1 ) && ( nFOOTAGE <= 1500 ))event.value = 250;

else if(( nFOOTAGE >= 1501 ) && ( nFOOTAGE <= 2000 )) event.value = 300;

else if(( nFOOTAGE >= 2001 ) && ( nFOOTAGE <= 2500 ))event.value = 325;

else if(( nFOOTAGE >= 2501 ) && ( nFOOTAGE <= 3000 ))event.value = 350;

else if(( nFOOTAGE >= 3001 ) && ( nFOOTAGE <= 3500 ))event.value = 375;

else if(( nFOOTAGE >= 3501 ) && ( nFOOTAGE <= 4000 ))event.value = 400;

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
July 19, 2019

Is this a single check-box? If so, it can only have one of two values, either "Off" or its export value.

Participating Frequently
July 19, 2019

yes its a single check box.

try67
Community Expert
Community Expert
July 19, 2019

So the entire second part of the code won't work. What should be the value of the field when the check-box is ticked?

Legend
July 19, 2019

First and foremost, there is no "Java" involved with Acrobat and PDF; it is JavaScript. All, Java and JavaScript have in common, are three letters.

The code may be accepted, but it is strongly suggested to use curly braces correctly. This definitely prevents ambiguities.

It also would help showing that this second line is incorrect. In Acrobat JavaScript, only one assignment character (aka "=") is allowed.