Hi All,
I have created a form that horizontially counts the number of non blank field using the following code
// array of field names to check
var aFields = new Array("1Row1","2Row1","3Row1","4Row1","5Row1","6Row1","7Row1","8Row1","9Row1","10Row1","11Row1","12Row1","13Row1");
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;
//to remove the 0
if (event.value==0) event.value="";
There are 15 of these counting cell, which then need to Summed to give a total.
The counting fields work fine but the sum does not and I can not use the simple select a field option as it shows the 0 instead of null.
I have tried variations of the following:
function SumArray(aFields){/* sum an Array of field namesParameter:
aFields = array of field names to sum
Returns sum of fields
*/var sum = 0; // result of summation of fields// loop through the array of field namesfor(i = 0; i < aFields.length; i++){// add value of i element from array of field namessum += Number(this.getField(aFields[i]).value);} // end of loopreturn sum;// return computed value // define an array of field names to sumvar aFieldNames = new Array("TotalforDayRow1","TotalforDayRow2","TotalforDayRow3","TotalforDayRow4","TotalforDayRow5","TotalforDayRow6","TotalforDayRow7","TotalforDayRow8","TotalforDayRow9","TotalforDayRow10","TotalforDayRow11","TotalforDayRow12","TotalforDayRow13","TotalforDayRow14","TotalforDayRow15");
//to remove the 0
if (event.value==0) event.value="";}
Could someone please let me know where I have gone wrong. I need the form to be blank so it can be printed as well and completed electronically.
I did the form in Acrobat 9 Pro but can put if into LiveCycle if that will help.
Thanks,
TiredEyes
Before checking if event.value == 0, you should apply the sum to it:
event.value = namessum;
if (event.value==0) event.value="";}
- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com