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

If, then validation scripts

New Here ,
Jul 17, 2019 Jul 17, 2019

Hi Guys, I'm a novice just starting with validation and calculation scripts.

I have a PDF form that has 5 calculated $ fields using calculation scripts. (we'll call them field, field2, field3, field4, field5)

I have a dropdown field that if the value selected is 1, the "amount due" field should return the value of field1

if value entered is 2, "amount due" field should return the value of field2

if value entered is 3, "amount due" field should return the value of field3

if value entered is 4, "amount due" field should return the value of field4

and if value entered is 5, "amount due" field should return the value of field5

I have tried everything I could find from reading several forums but I keep getting errors.

Can someone PLEASE help?

Thank you in advance 

TOPICS
PDF forms
4.3K
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 17, 2019 Jul 17, 2019

Let's say it's called "Dropdown1". You can use this code as the custom calculation script of "Amount Due":

var v = this.getField("Dropdown1").valueAsString;

if (v=="1") event.value = this.getField("field1").valueAsString;

else if (v=="2") event.value = this.getField("field2").valueAsString;

else if (v=="3") event.value = this.getField("field3").valueAsString;

else if (v=="4") event.value = this.getField("field4").valueAsString;

else if (v=="5") event.value = this.getField("field5").valueAsString;

else event.value = "";

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 17, 2019 Jul 17, 2019

What's the name of the dropdown field?

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 17, 2019 Jul 17, 2019

Let's say it's called "Dropdown1". You can use this code as the custom calculation script of "Amount Due":

var v = this.getField("Dropdown1").valueAsString;

if (v=="1") event.value = this.getField("field1").valueAsString;

else if (v=="2") event.value = this.getField("field2").valueAsString;

else if (v=="3") event.value = this.getField("field3").valueAsString;

else if (v=="4") event.value = this.getField("field4").valueAsString;

else if (v=="5") event.value = this.getField("field5").valueAsString;

else event.value = "";

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

try67

AMAZING!!! All I can say. I have spent over 4 hours reading and trying out different validation scripts on the dropdown field (Not the Amount Due) as some forums recommended and nothing worked.

I cant thank you enough!!

Joe

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
New Here ,
Feb 22, 2023 Feb 22, 2023

Hi! I am doing something similar, and also very new. The differencebetween mine and this post, I only have 1 if statement, and I want it to be if the value is less than the value of "field1" then it shows the value entered in "Dropdown1"

 

This is what I have, and there is no output into the "AmountDue" field

 

var v = this.getField("Dropdown1").valueAsString;
if (v < "13461.75") event.value = this.getField("field1").valueAsString;

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 ,
Feb 22, 2023 Feb 22, 2023

You are using string instead of number, try like this:

var v = Number(this.getField("Dropdown1").valueAsString);
if (v < 13461.75) event.value = this.getField("field1").value;

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
New Here ,
Feb 22, 2023 Feb 22, 2023

Thank you, the AmountDue field still shows up empty after entering this. Would it have any effect if the value of "Dropdown1" is the product of 2 other fields?

 

if it is any consollatoin, The value of "Field1" will always be 13461.75

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 ,
Feb 22, 2023 Feb 22, 2023

If a field is named "Field1" then in your script change f to uppercase.

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
New Here ,
Feb 22, 2023 Feb 22, 2023

Still nothing 😞 Maybe this picture will help?

What I have typed in the Javascript is literally this, only the 2 lines, debugger is giving me a syntax error.

 

var v = Number(this.getField("Dropdown1").valueAsString);
if (v < 13461.75) event.value = this.getField("Field1").value;

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 ,
Feb 22, 2023 Feb 22, 2023

Can you share the actual file or create a sample file with just those fields and post that?

Why do you use the dropdown field for multiplication, and how did you set that to work?

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
New Here ,
Feb 22, 2023 Feb 22, 2023

Attached is the example document. The two are multiplied because it is calculating a rate. I named the fields as such just for the simplicity of matching the original post.

 

How they are multiplied is through the calculation tab of properties, and it is a product of those 2 fields.

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 ,
Feb 22, 2023 Feb 22, 2023
LATEST

Use script as calculation, not validation.

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

Invoice #

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 17, 2019 Jul 17, 2019

Then insert that into the quotes in the first line of the code I posted above.

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