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

Check box runs a script in another field

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

1.4K

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

Votes

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
community guidelines
Community Expert ,
Jul 19, 2019 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.

Votes

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

Copy link to clipboard

Copied

yes its a single check box.

Votes

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
community guidelines
Community Expert ,
Jul 19, 2019 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?

Votes

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

Votes

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
community guidelines
Community Expert ,
Jul 19, 2019 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;

}

Votes

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

Votes

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
community guidelines
Community Expert ,
Jul 19, 2019 Jul 19, 2019

Copy link to clipboard

Copied

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

Votes

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

Votes

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
community guidelines
Community Expert ,
Jul 19, 2019 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.

Votes

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
community guidelines
Community Expert ,
Jul 19, 2019 Jul 19, 2019

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

LATEST

That did it!!!

You are awesome.. thank you!!

Votes

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
community guidelines