I am doing what I thought was a straightfoward calculation, but something weird is happening. This is a form that adds up insurance premiums and subtracts one field. I am using a script to add an extra $35 if the swimimng pool checkbox is set to yes. It works fine if I enter premiums then check the box. However, if I check the box first then enter premiums, the math goes haywire.
For example, if I check the box, the total goes to $35, which is correct, but if I then enter $100 in the first premium field, the total goes to $10,035 instead of $135.
I am using Acrobat Pro 9. I have placed this code in the custom calculation field...
//add pool surcharge to total
if
(this.getField("swimmingPool").value == "Yes") {
event.value = this.getField("premium_calc").value + this.getField("autoCredit").value + 35;
}else {event.value = this.getField("premium_calc").value + this.getField("autoCredit").value;
}
This forces the values into the correct context. However for it to work the initial values for the fields have to be 0, not empty strings, which is what probably caused the calc to be in a string context in the first place.
Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]
The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]
Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script