Skip to main content
Participating Frequently
May 5, 2020
Answered

Fillable Form Javascript

  • May 5, 2020
  • 2 replies
  • 2022 views

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! 

This topic has been closed for replies.
Correct answer try67

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?

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 5, 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?

MadyB88Author
Participating Frequently
May 5, 2020

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

try67
Community Expert
Community Expert
May 5, 2020
// 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;
Bernd Alheit
Community Expert
Community Expert
May 5, 2020

Start learning Javascript.

To get the value of a field use:

this.getField (" field name ").value

 

MadyB88Author
Participating Frequently
May 5, 2020

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

Bernd Alheit
Community Expert
Community Expert
May 5, 2020