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

Sum text boxes that a Check Box refers to

MACY8167
Registered: Sep 25 2010
Posts: 7

I have check boxes labled "suc1", "suc2" etc. They are next to Text boxes labled "su1". "su2" etc . At the bottom is a Total Text box. I would like it to sum all of the text boxes that have a check next to them.
 
This is what I have so far but I am gettin errors. Or maybe I am making this too hard and there is an easier way of getting this done. ANY help is greatly appreciated!
 
event.value = "";
var sum = 0;
if(this.getField("suc1").value=="Yes”)event.value=
sum += +getField ("su1").value;
if(this.getField("suc2").value=="Yes”)event.value=
sum += +getField (“su2”).value;
if(this.getField("suc3").value=="Yes”)event.value=
sum += +getField (“su3”).value;
if( !NaN(su1))
sum += (0);

My Product Information:
Acrobat Pro 9.0, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
What errors are you getting?

Try:

var sum = 0;
for(i = 1; i < 4; i ++) {
if(this.getField("suc" + i ).value !="Off") sum += Nmber(this.getField ("su" + i).value);
}

if(sum == 0) event.value = '';
else event.value = sum;

George Kaiser

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Try the following, which is intended to be a custom Calculate script for a text field:



// Initialize variable
var sum = 0;

// Add the field value if the corresponding check box is selected
if(getField("suc1").value !== "Off") sum += +getField("su1").value;
if(getField("suc2").value !== "Off") sum += +getField("su2").value;
if(getField("suc3").value !== "Off") sum += +getField("su3").value;

//Set this field's value
event.value = sum;

MACY8167
Registered: Sep 25 2010
Posts: 7
Thank you both for your help. I had a little trouble getting the first one to work(due to my lack of knowledge I'm sure). The second one is working great! Thanks you so much to both of you for taking the time to answer!!!!