These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Javascript calculation

Rulon
Registered: Aug 20 2008
Posts: 3

I have a 'Subtotal' field that calculates OK and then a field where the user enters a value for, 'I already paid ($).'

There are 2 Total fields.

So, the Total1 field should be 'Subtotal' minus 'Advance'

The tricky part, is if the user already paid MORE than the Subtotal, Total2 field should calculate 'We owe you' and make Total1 show zero.

I'm new to LiveCycle, but this is the script that has been done in Acrobat:

Total1

var SubTotal=this.getField("SubTotal");
var Advance=this.getField("Advance");
var n=0;

//Check for a negative value
if (SubTotal.value - Advance.value > 0)
{event.value = (SubTotal.value - Advance.value)
}
else event.value = 0

Total2

var SubTotal=this.getField("SubTotal");
var Advance=this.getField("Advance");

//Check for a positive value
if (SubTotal.value - Advance.value < 0)
{ event.value = (Advance.value - SubTotal.value)
}
else event.value = 0

event is calculate: - (JavaScript, client)

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
If you are using LiveCycle Designer, you should not be using Acro Forms JavaScript. LiveCycle Designer includes scripting references under the menu bars "Help" option.

George Kaiser

formman
Registered: Jul 17 2008
Posts: 44
Roulon,

Here is a JS conversion from AcroForms JS to XFA JS. There are a number of potential problems that might happen especially if the Total1 field is not in the same subform as the SubTotal and Advance fields.

Hope this helps.

Rick Kuhlmann


Total1

//Check for a negative value
var n = SubTotal.rawValue - Advance.rawValue;
if (n > 0)
{
this.rawValue = n;
} else this.rawValue = 0 //assumes you want Total1 to be 0


Total2

//Check for a negative value
var n = SubTotal.rawValue - Advance.rawValue;
if (n < 0)
{
this.rawValue = (Advance.rawValue - SubTotal.rawValue);
} else this.rawValue= 0; //assumes you want Total2 to be 0


event is calculate: - (JavaScript, client)

Forms Developer/Designer
Tech-Pro, Inc.
Roseville, MN