You should use "valueAsString" instead of "value" and then use the comparison != "" to remove null fields values.
If you can use arrays for the values you can then filter out the null strings.
amazing! It works - so simple, thank you!
Oh - spoke to soon. More testing required, not working at all now!!
So I have tried various different ways of switching 'value' for 'valueAsString' and using the comparison !="" but I still don't get a result unless all the fields have data in them?
The following code should put the non-null values into an array and then process that array through your function and sum the results. Note that each individual field is tested for being not null and only added to the array of values to process when the value is non-null.
// array of cut field names;
var aCuts = new Array("CUT 1", "CUT 2", "CUT 3", "CUT 4",
"CUT 5", "CUT 6", "CUT 7", "CUT 8", "CUT 9", "CUT 10");
// fieldname prefix;
var cPrefix = "P1.Spawn page.P1.Actions page.";
// field object for loop processing;
// array for non-null values;
var aCutValues = new Array();
// loop to fill array of non-null values;
for(var i = 0; i < aCuts.length; i++)
var oField = this.getField(cPrefix + aCuts[i]);
if(oField.valueAsString != "")
} // end non-null value;
} // next field to process;
// now process non-null values;
// variable for sum of the individual values;
nSum = 0;
// process array of non-null values;
for(var i = 0; i < aCutValues.length; i++)
nSum += timecode_to_frames(Number(aCutValues[i]));
} // next cut value in array;
event.value = "";
if(nSum != 0) event.value = nSum;
With so many fields and functions. a link to the form or a sample form would be helpful for testing.
Thank you - I really appreciate your help with this. I have put the script you supplied into a sample form and here is a link:
Hi thank you for this script but I can't get it to work at all - assuming this should still be placed in the custom calculation script field?
Hello guys! Need your help please! Here is a similar problem.
Thank you for your help!
Do you know how to do this in Excel, especially for division?
I would look at using the "Validation" tab in the "Properties" pop-up window for the result field and use a script like:
// if field value is zero, replace with a null string;
if(event.value == 0) event.value = "";
It works!!!! Thanks a lot!!! You have saved my life
In excel it was easy! But I've decided to do a same form in pdf, so I can use it on mobile devices... And then this problem came out!
Testing it now