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

Combo Box -Sum If

MACY8167
Registered: Sep 25 2010
Posts: 7

I have a combo box that a user can select either "Company" or "Employee". Based upon their selection I would like to sum several text fields(the user enters values in these fields). The result would appear in either the "Company Total" text box or "Employee Total" text box. I have search for a similiar situation but haven't found anything that will work. Any help is greatly appreciated.

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
In the two total fields, you could set up custom Calculation script that look something like:

// Calculate script for Company field
(function () {

// Get the value of the combo box
var c_val = getField("your_combo").value;
var sum = 0;

if (c_val === "Company") {

// Calculation code goes here, e.g.,
sum += +getField("text1").value;
sum += +getField("text2").value;
sum += +getField("text3").value;
// etc.

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

} else {
// Clear field
event.value = "";
}

})();


Replace "your_combo" with the name of the comb box you're using, and adjust the summing code above to suit your needs. The summing code above assumes the fields are numeric.
MACY8167
Registered: Sep 25 2010
Posts: 7
Thanks so much for your help. I have added the below code to the "total" text box but nothing happened. I am pretty sure I missed something stupid but just in case something jumps out at you I pasted the code below. Either way I will keep playing with it. Thanks!


// Calculate script for Company field
(function () {

// Get the value of the combo box
var c_val = getField("pb0").value;
var sum = 0;

if (c_val === "Company") {

// Calculation code goes here, e.g.,
sum += +getField("su1").value;
sum += +getField("m1").value;
sum += +getField("tu1").value;
sum += +getField("wu1").value;
sum += +getField("th1").value;
sum += +getField("f1").value;
sum += +getField("s1").value;





// etc.

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

} else {
// Clear field
event.value = "";
}

})();

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Where did you place the code, exactly? It is supposed to be used as the field's custom Calculate script, as opposed to Validate, Mouse Up, or something else. Also, it will get triggered when you change one of the form's field values. If the input fields are empty and/or the combo box value is not "Company", the field will be blank.
MACY8167
Registered: Sep 25 2010
Posts: 7
It is working, I had one of the the text boxes I was adding keyed wrong should have been "w1" not "wu1" . Once again thanks for your help!!!!!!!!!!!!!!!!!!!!