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

JavaScript calculations

tjinjax
Registered: Jan 11 2007
Posts: 10

I have the need to run a simple calculation on a form. The first three elements that may/may not factor in a value are checkboxes. I'm not a developer so this process is fuzzy for me. I'd like to know what I add to this statement to include/exclude their value whether or not it's checked. event.value = ( this.getField("CheckBox.14").value +
this.getField("CheckBox.15").value +
this.getField("CheckBox.16").value ) -
this.getField("Text5").value +
this.getField("Text8").value;
 
Thanks!

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
First, checkboxes do not have a numerical value so they can't be used like this. I don't know exactly what you are trying to do but the calculation script could be structured like this:

event.value = 0;if(this.getField("CheckBox.14").isBoxChecked(0))event.value += 1; // Add one if(this.getField("CheckBox.15").isBoxChecked(0))event.value += 1; // Add one if(this.getField("CheckBox.16").isBoxChecked(0))event.value -= this.getField("Text5").value + this.getField("Text8").value; // Subtract text Fields
This is one way that check boxes can be used in a calculation.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script