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

Acrobat If, Else, Then statement

Contributor ,
Jul 11, 2022 Jul 11, 2022

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
2.5K
Translate
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
1 ACCEPTED SOLUTION
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;

View solution in original post

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

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

Translate
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

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

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

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

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.

Translate
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

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

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

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

 

Untitled-2.png

Translate
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

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

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

Sorry.  I don't understand.

Translate
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

To quote:

 

quote

on the validate of the Value 3

Translate
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
Contributor ,
Jul 14, 2022 Jul 14, 2022
LATEST

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

Translate
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