11 Replies Latest reply on Oct 26, 2010 3:17 PM by gkaiseril

# Count Field Calculation

Hello and thank you in advance for your time. I am looking for a formula that will count the number of fields containing text.

Example:

Field1 = "text"
Field2 = "text"
Field2 = "text"

TotalCount = 3

Any assistance will be greatly appreciated.

Thank you again and have a great day!
• ###### 1. Re: Count Field Calculation
Try the following JavaScript in AroForms:

// array of field names to check
var aFields = new Array("Text1", "Text2", "Text3");
var count = 0; // variable to store count of non-empty fields
for (i = 0; i < aFields.length; i++) {
if (this.getField(aFields[i]).valueAsString != "") count++
} // end loop
event.value = count;

LiveCycle Designer can use the same logic but the syntax will be different.
• ###### 2. Re: Count Field Calculation
Worked like a charm! You are a ROCK STAR! Thank you, thank you, thank you!
• ###### 3. Re: Count Field Calculation
How did you know Geo was a rock star? He plays bass in a punk metal band called "PDF-U".
• ###### 4. Re: Count Field Calculation
Does anyone know how or if it is possible to calculate the number of days between two dates in Adobe Designer? For example: date1 - date2 = 10 days) If so, what is the formula? Thanks!!
• ###### 5. Re: Count Field Calculation
Yes, but you have to convert the date strings to the number of days using the Date2Num() funciton.
• ###### 6. Re: Count Field Calculation
Count Field
I am trying to add numbers across a table and come up with a total
for all cell entries.
I cannot seem to get it to caculate. Does anyone know what I am doing wrong?
• ###### 7. Re: Count Field Calculation
You will get more responses by starting a new post with a meaningful title.

You should also provide more information about what your particular situation. Like which product are you using, AcroForms or LiveCycle Designer. And if LiveCycle Designer, are your forms dynamic or static?
• ###### 8. Re: Count Field Calculation

How do i stop from counting non-number

• ###### 9. Re: Count Field Calculation

You can use the JavaScript 'isNaN()' method to test to see if a string has a non-numeric value. The null string will be treated like zero, so if you do not want to include an empty string, you will need to test for it. You could use the 'valueAsString' property to sort out strings with a zero entry and an empty or null string.

• ###### 10. Re: Count Field Calculation

Thanks for the reply.. I am very green at Java script an tried variations of scrpt to aviod counting fields.. How would a NAN() fit into your original count command? reference Mar 5, 2008 response to Randy_Street

• ###### 11. Re: Count Field Calculation

If the fields are formatted as a numeric value, then using the 'valueAsString' property will detect a null field and allow one to test for the null value. If the 'valueAsString' was not used the null value would equate to zero.

There is no non-constrictor function of "NaN()' , it is "isNaN()' or is Not A Number function.

Core Function

Evaluates an argument to determine if it is not a number.

### Syntax

`isNaN(testValue) `

`ParameterstestValue  The value you want to evaluate. DescriptionisNaN is a top-level function and is not associated with any object.isNaN attempts to convert the passed parameter to a number. If the parameter can't be converted, it returns true; otherwise, it returns false. CAVEAT : if the parameter is null or an empty string or unicode spaces, it returns false ! So if you are trying to eliminate field that have no imput, a null, value, you can not use the 'isNaN()' function. `