Fillable Form Javascript

Community Beginner ,
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! 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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?

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

539

Likes

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

Fillable Form Javascript

Community Beginner ,
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! 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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?

TOPICS
Acrobat SDK and JavaScript, How to, PDF forms

Views

540

Likes

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
May 04, 2020 0
Adobe Community Professional ,
May 04, 2020

Copy link to clipboard

Copied

Start learning Javascript.

To get the value of a field use:

this.getField (" field name ").value

 

Likes

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
Reply
Loading...
May 04, 2020 0
Community Beginner ,
May 04, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
May 04, 2020 0
Adobe Community Professional ,
May 04, 2020

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
May 04, 2020 0
Community Beginner ,
May 04, 2020

Copy link to clipboard

Copied

Thank you very much for your help!

Likes

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
Reply
Loading...
May 04, 2020 0
Most Valuable Participant ,
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?

Likes

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
Reply
Loading...
May 05, 2020 1
Community Beginner ,
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

Likes

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
Reply
Loading...
May 05, 2020 0
Most Valuable Participant ,
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;

Likes

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
Reply
Loading...
May 05, 2020 1
Community Beginner ,
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

Likes

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
Reply
Loading...
May 05, 2020 0
Most Valuable Participant ,
May 05, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
May 05, 2020 0
MadyB88 LATEST
Community Beginner ,
May 05, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
May 05, 2020 0