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!
Copy link to clipboard
Copied
Start learning Javascript.
To get the value of a field use:
this.getField (" field name ").value
Copy link to clipboard
Copied
I want to learn javascript not sure where, hence asking the experts.
Copy link to clipboard
Copied
To debug code:
Copy link to clipboard
Copied
Thank you very much for your help!
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?
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
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;
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
Copy link to clipboard
Copied
That means one of the fields is not named as you've specified.
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!!