6 Replies Latest reply on Apr 9, 2012 4:46 AM by Rspartridge

Hi,

The following question seems to be a popular one but as I have absolutely no understanding of JavaScript could someone point me in the right direction please.

I have a form which has 15 sections namely, Margin, Margin2, Margin3,...and so on until Margin15.  Within these sections is numeric figure and I need to average these whilst ignoring "0.00".

Many thanks,

R

• 1. Re: Help with JavaScript please?

Are you talking about a LC form, or one created in Acrobat? If Acrobat, I'm

not sure what you mean by "sections"....

At any case, the approach would be to create a loop that goes over all of

the fields, checking that they are not empty or zero, and if so summing

them up while maintaining a counter of how many fields were totaled. Then

you just divide the sum by the value of the counter.

• 2. Re: Help with JavaScript please?

I've created the form in Acrobat.

You've outlined the approach correctly but I have no idea how go about this in JavaScript. Do you know the language?

• 3. Re: Help with JavaScript please?

Yes, I do. What are the names of the text fields?

• 4. Re: Help with JavaScript please?

Margin, Margin2, Margin3,...and so on until Margin15.  Within these sections is a numeric figure and I need to average these whilst ignoring "0.00".

• 5. Re: Help with JavaScript please?

Rename the first field to "Margin1", and then you could use this code as the custom calcluation code of your average field:

var counter = 0;

var sum = 0;

for (var i=1; i<=15; i++) {

var v = +this.getField("Margin"+i).value;

if (v!=0) {

counter++;

sum += v;

}

}

if (counter==0)

event.value = "";

else event.value = sum / counter;

• 6. Re: Help with JavaScript please?

Excellent - you are my savour.  Many an hour wasted frustrating over this and solved within a couple of minutes. Thank you.