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

If then Calculator script help

Gattaca714
Registered: Dec 16 2009
Posts: 25
Answered

I have 4 fields:
 
Total
NumberField1
NumberField2
MathSign
 
What I'm trying to do is make a simple calculator on my form. Here is my code that I have in my "Total" Numeric Field. Event is Calculate. Language is JavaScript.
 
-----------------
var a = this.getField("form1.BallotOrder.MathSign");
var b = this.getField("form1.BallotOrder.NumberField1");
var c = this.getField("form1.BallotOrder.NumberField2");
 
if (a.value == "+" ) then (b.event.value) + (c.event.value);
if (a.value == "-" ) then (b.event.value) - (c.event.value);
if (a.value == "*" ) then (b.event.value) * (c.event.value);
if (a.value == "/" ) then (b.event.value) / (c.event.value);
if (a.value == "Clear" ) then 0 * 0;
 
endif
 
-----------------
 
Any leads on why my code doesn't work would be appreciated.
 
Thanks,
 
Rigo

My Product Information:
LiveCycle Designer, Windows
Bamboolian
Registered: Jul 27 2010
Posts: 48
Hi,

1. change ".value" to "rawValue"
2. change "then endif" to "{}"
3. need to set value to "this.rawValue"

Script will be like following;

if (TextField1.rawValue == "+"){
this.rawValue = NumericField1.rawValue + NumericField2.rawValue;
}else if(TextField1.rawValue == "-"){
this.rawValue = NumericField1.rawValue - NumericField2.rawValue;
}else if(TextField1.rawValue == "*"){
this.rawValue = NumericField1.rawValue * NumericField2.rawValue;
}else if(TextField1.rawValue == "/"){
if ((NumericField2.rawValue == null) || (NumericField2.rawValue == 0)){
this.rawValue = 0;
}else{
this.rawValue = NumericField1.rawValue / NumericField2.rawValue;
}
}else if(TextField1.rawValue == "Clear"){
this.rawValue = 0;
}
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Accepted Answer
Since you are using LiveCycle Designer, do you want to use FormCalc or JavaScirpt.

JavaScirpt:

var a = MathSign.rawValue;
var b = NumberField1.rawValue;
var c = NumberField2.rawValue;

if (a == "+" ) $.rawValue = b + c;
if (a == "-" ) $.rawValue = b - c;
if (a == "*" ) $.rawValue = b * c;
if (a == "/" ) $.rawValue = b / c;
if (a == "Clear" ) xfa.host.resetData(["NumberField1", "NumberField2", "Total", "MathSign"]);


FormCalc:

if (MathSign == "+" ) then
$ = NumberField1 + NumberField2
elseif (MathSign == "-" ) then
$ = NumberField1 - NumberField2
elseif (MathSign == "*" ) then
$ = NumberField1 * NumberField2
elseif (MathSign == "/" ) then
$ = NumberField1 / NumberField2
elseif (MathSign == "Clear") then
xfa.host.resetData("NumberField1, NumberField2, Total, MathSign")
endif


George Kaiser

Gattaca714
Registered: Dec 16 2009
Posts: 25
The FormCalc method is a cleaner solution and worked without skipping a beat.

Thanks for you help George and Bamboolian.

:)