Highlighted

Check box runs a script in another field

New Here ,
Jul 19, 2019

Copy link to clipboard

Copied

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;

Topics

Acrobat SDK and JavaScript

Views

460

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

Check box runs a script in another field

New Here ,
Jul 19, 2019

Copy link to clipboard

Copied

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;

Topics

Acrobat SDK and JavaScript

Views

461

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
Advocate ,
Jul 19, 2019

Copy link to clipboard

Copied

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.

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...
Most Valuable Participant ,
Jul 19, 2019

Copy link to clipboard

Copied

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

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...
New Here ,
Jul 19, 2019

Copy link to clipboard

Copied

yes its a single check box.

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...
Most Valuable Participant ,
Jul 19, 2019

Copy link to clipboard

Copied

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?

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...
New Here ,
Jul 19, 2019

Copy link to clipboard

Copied

When the box is clicked I want the values based on the footage inserted.

i.e.footage  >1 but < 1500 = 250 and so on

When the box is empty field can be empty or zero.

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...
Most Valuable Participant ,
Jul 19, 2019

Copy link to clipboard

Copied

Ah OK, I get it now. Then you can use this code:

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

else {

    var nFOOTAGE = Number(this.getField("FOOTAGE").valueAsString);

    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;

}

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...
New Here ,
Jul 19, 2019

Copy link to clipboard

Copied

The script was accepted but nothing appears in the event field (RIP)

FOOTAGE field is just a number field

Check box name is RICheckBox

Event Field is named RIP.

Formula is in calculate tab in RIP field.

by the way... I really appreciate your help with this...

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...
Most Valuable Participant ,
Jul 19, 2019

Copy link to clipboard

Copied

Check the JS Console for error messages (Ctrl+J).

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...
New Here ,
Jul 19, 2019

Copy link to clipboard

Copied

TypeError: this.getField(...) is null

1:Field:Mouse Enter

SyntaxError: missing } in compound statement

9:

SyntaxError: missing } in compound statement

9:

TypeError: this.getField(...) is null

1:Field:Calculate

TypeError: this.getField(...) is null

1:Field:Mouse Enter

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...
Most Valuable Participant ,
Jul 19, 2019

Copy link to clipboard

Copied

JS is case-sensitive. You need to change the "b" in "box" to a "B" to match the actual field name.

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...
Most Valuable Participant ,
Jul 19, 2019

Copy link to clipboard

Copied

PS. This code should be a calculation script, not a "Mouse Enter" script...

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...
New Here ,
Jul 19, 2019

Copy link to clipboard

Copied

That did it!!!

You are awesome.. thank you!!

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...
Resources
One Stop Solution for Acrobat
Edit a PDF
Add a group