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

If, then validation scripts

New Here ,
Jul 17, 2019 Jul 17, 2019

Copy link to clipboard

Copied

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

Views

2.1K

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

...

Votes

Translate

Translate
Community Expert ,
Jul 17, 2019 Jul 17, 2019

Copy link to clipboard

Copied

What's the name of the dropdown field?

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

Copy link to clipboard

Copied

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 = "";

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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;

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

Copy link to clipboard

Copied

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;

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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;

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

LATEST

Use script as calculation, not validation.

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

Copy link to clipboard

Copied

Invoice #

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

Copy link to clipboard

Copied

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

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