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

Acrobat If, Else, Then statement

Participant ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

Hi 

I am new to PDF scripts and am trying to create one for a form, but getting a little confused with other examples.

 

Here is what I require.

 

1. Simple calculation Value 1 + Value 2 = Value 3 (This bit I can do 🙂 )

2. This is the bit I need help on.

   Value 3 will sit in Band, named A to I. So I need a script that displays the Band value 3 fits in?

 

example Value 3 = 10000.

Band A is up to 1000

Band B is between 1000 & 5000

Band C is between 5000 & 15000, 

 

so Value 3, sits in Band C, so I display a C

 

I hope this is clear?

Mark

TOPICS
JavaScript

Views

1.2K

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

correct answers 1 Correct answer

Community Expert , Jul 12, 2022 Jul 12, 2022

Hi, 

 

on the validate of the Value 3 you should be able to do something like 

 

var bandValue = "";
if ( event.value < 1000){
  bandValue = "A";
} else if (( event.value >= 1000) && ( event.value < 5000)){
  bandValue = "B";
} else if ((event.value >=5000) && ( event.value < 15000)){
  bandValue = "C";
} else {
  //catch all in case the value is not any of above
  bandValue = "ERROR"
}
// change "BandValue" to the name of your field.
this.getField("BandValue").value = bandValue;

Votes

Translate

Translate
Community Expert ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

Hi, 

 

on the validate of the Value 3 you should be able to do something like 

 

var bandValue = "";
if ( event.value < 1000){
  bandValue = "A";
} else if (( event.value >= 1000) && ( event.value < 5000)){
  bandValue = "B";
} else if ((event.value >=5000) && ( event.value < 15000)){
  bandValue = "C";
} else {
  //catch all in case the value is not any of above
  bandValue = "ERROR"
}
// change "BandValue" to the name of your field.
this.getField("BandValue").value = bandValue;

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
Participant ,
Jul 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

Hi

 

Thank you for the help. This is great. Unfortunately, I just keep getting an error.

 

How does the code know it is working with Value 3?

 

Thanks

Mark

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 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

Because it's associated with it via the event that it triggers.

What does the error you're getting say, exactly?

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
Participant ,
Jul 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

I just says error

 

Untitled-1.png

 

Do i need to change all BandValues to Value D or just the last one?

 

Sorry, I really don't know what I am doing.

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 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

Ah, the field itself says "ERROR", I see. Where did you place the code, exactly?

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
Participant ,
Jul 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

I put it in the custom script box, though it wont work now!

 

Untitled-2.png

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 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

It's the wrong field and the wrong event. Read the original reply more carefully.

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
Participant ,
Jul 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

Sorry.  I don't understand.

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 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

To quote:

 

quote

on the validate of the Value 3

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
Participant ,
Jul 14, 2022 Jul 14, 2022

Copy link to clipboard

Copied

LATEST

I'm sorry. I'm a fool. Thank you for your help. It works now. 🙂

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