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
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;
}