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

Fillable Form Javascript

Community Beginner ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

Hi,

 

I need to create a claim form but struggling with the java script to display the correct info.

1. The text box must display the amount being paid.

"Type1" is a drop down menu with 6 selections, how do I add the other 5 options information in the script? This is what I was thinking:

If ("Type1" = "PPC") then ("Text8" = "$120")

or 

If ("Type1" = "APT") then ("Text8" = "R950")

 

2. I need to calculate the total amount for each currency in the 11 text boxes. What would the script be?

 

Thank you in advance for your help! 

TOPICS
Acrobat SDK and 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 , May 05, 2020 May 05, 2020

For #1 use the following code as the custom calculation script of "Text8":

 

var type1 = this.getField("Type1").valueAsString;

if (type1=="PPC") event.value = "$120";

else if (type1=="APT") event.value = "R950";

else event.value = "";

 

For #2, what are the names of the fields involved?

Votes

Translate

Translate
Community Expert ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

Start learning Javascript.

To get the value of a field use:

this.getField (" field name ").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 Beginner ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

I want to learn javascript not sure where, hence asking the experts. 

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 ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

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 Beginner ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

Thank you very much for your help!

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 ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

For #1 use the following code as the custom calculation script of "Text8":

 

var type1 = this.getField("Type1").valueAsString;

if (type1=="PPC") event.value = "$120";

else if (type1=="APT") event.value = "R950";

else event.value = "";

 

For #2, what are the names of the fields involved?

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 Beginner ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

Thank you!!

The name the fields are:

Total1

Total2

Total3

Total4

Total5

Total6

Total7

Total8

Total9

Total10

Total11

 

And then it must be displayed in TotalRand and TotalDollar

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 ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

// TotalDollar calc script
var total = 0;
for (var i=1; i<=11; i++) {
	var f = this.getField("Total"+i);
	var v = f.valueAsString;
	if (/^\$/.test(v)) total+=Number(v.replace("$", ""));
}
event.value = total;

// TotalRand calc script
var total = 0;
for (var i=1; i<=11; i++) {
	var f = this.getField("Total"+i);
	var v = f.valueAsString;
	if (/^R/.test(v)) total+=Number(v.replace("R", ""));
}
event.value = total;

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 Beginner ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

Thank you soo much for your help!!

 

If I enter thatcode it gives me this error:

 

TypeError: f is null
4:Field:Calculate
TypeError: f is null
4:Field:Calculate

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 ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

That means one of the fields is not named as you've specified.

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 Beginner ,
May 05, 2020 May 05, 2020

Copy link to clipboard

Copied

LATEST

thank you very much, I misspelled total on one of the text boxes. I really appreciate your time and help!!

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