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

test boxes with zeros "0"

Elya42
Registered: Mar 3 2009
Posts: 59
Answered

I need a script that I can put in a text box that will count all other text boxes that contain Zero "0".

I have tried to use vaidation but that does not work. I just cannot get the custom calucation script to count the zero.

Elaine M

My Product Information:
Acrobat Pro 9.1, Macintosh
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Are you counting only zero values or zero values and null values?

What is your code?

// array of field names to processaFieldNames = new Array("Field.0", "Field.1", "Field.2", "Field.3");var fZeroNull = 0; // count of feilds with zerovar fZero = 0; // count of zero valuesvar fNull = 0; // count of null valuesvar fNonZero = 0; // non-zero/non-null count// loop through field namesfor(i = 0; i < aFieldNames.length; i++) {// count zero or null valuesif (this.getField(aFieldNames[i]).value == 0) fZeroNull++// count only zerosif (this.getField(aFieldNames[i]).valueAsString == "0") fZero++// count only null valuesif (this.getField(aFieldNames[i]).value.toString() =="") fNull++// count non-zero/non-null fieldsif (this.getField(aFieldNames[i]).value != 0) fNonZero++}event.value = fZero; // show the detailed resultsconsole.show();console.clear();console.println("Zero or Null count: " + fZeroNull);console.println("Zero count: " + fZero);console.println("Null count: " + fNull);console.println("Non-Zero/Non-Null count: " + fNonZero);

George Kaiser

Elya42
Registered: Mar 3 2009
Posts: 59
I tried this (I am sure I am not doing any of this correctly)

I do rember what I tried but it does not look anything like your script

I am only needing the Zero values counted

Elaine M

Elya42
Registered: Mar 3 2009
Posts: 59
I have attempted to use the code you provided - I am getting a syntax error with the followig line -

"// loop through fieldnames"

Elaine M

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Have you changed the field names from those of the example to your field names?

Capitalization, punctuation, spelling are all critical.

George Kaiser

Elya42
Registered: Mar 3 2009
Posts: 59
Yes. I managed to fix the error message and when I tested it by entering zeros in to the the comboboxes and textboxes - no results showed.

Elaine M

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
It works for text fields with the names I used (Field.0, Field.1, Field.2, Field.3) and the text fields set to a number format. If you are going to have combo box, you need to have a unique numeric export value assigned to each option of the combo box. Spaces are not the same as a null or zero.

Are you getting anything displaying in the JavaScript debugging console?

George Kaiser