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

Percent calculation does not stay once I reset form

jaynefergs
Registered: Nov 11 2008
Posts: 37
Answered

George,
The calcualtion works, but when I save it my total hours worked loses its total.
I deleted the "O" factor, sample below

var v1 = getField("Total TPP Hours").value;
var v2 = getField("Total Hours Worked").value;

// Perform calculation and set this field value
event.value = v1 / v2;

It works perfect, except when I open a new form I get a Javascript message:

The valve entered does not match the format of the field [Percentage]. If I click okay and just fill out form it works? I just get message when opening and saving? Any suggestions??? Jayne

My Product Information:
Acrobat Pro 8.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
If you get rid of that test for zero, what happens is the calculation attempts to divide by zero, since the value in "Total Hours Worked" is zero. Since the result of division by zero is not a (finite) number, you are getting that error. The reason I included the code that test for a value of zero is to prevent just this.

I'm not sure why the field value is not retained when you save and reopen. Are you using a Reset Form action anywhere?

George
jaynefergs
Registered: Nov 11 2008
Posts: 37
Yes I am using a reset form button
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
If you change the percentage field to a format of "None" you will see how Acrobat is handling this issue.

If you leave the total hours emptyor enter a zero:

Entering nothing or zero in the hours worked results in 'NaN', Not a Number.
Entering 1 or other positive number results in 'Infinity'.
Entering -1 or other negative number results in '-Infinity'.

Entering any number except zero in the total hours worked will result in a computed value.

Resetting the form is changing the total hours worked to a null string (empty value) and this value is treated like a zero in computations. So you need to test for the total hours worked not being a null or a zero value and then perform the calculation. And if it is a null or a zero value then you can not perform the calculation. And if you do not want to show the result, you could then hide for form field.

George Kaiser

jaynefergs
Registered: Nov 11 2008
Posts: 37
Okay that is the problem. When I reset total hours worked goes back to zero,
and if I make the percentage none, it comes back with NaN.

The form is used per month with 8 hour days, weekend off, holidays off, sick day and/or sick leave. Since every month has different scenrios, it has to go back to the zero.

Like I said it works and saves the hours when I take the "0" out, but I get that java message. That will not work, when you have multiple staff using this form.

Any hope in making it work?
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Why did you remove the test for zero in the script?

George
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
If you use this for the custom calculation script:

var v1 = getField("Total TPP Hours").value;
var v2 = getField("Total Hours Worked").value;
// Perform calculation and set this field value if total hours not zero
if (v2 != 0) {
event.value = v1 / v2;
} else {
event.value = 0; // else force the result to zero
}

George Kaiser

jaynefergs
Registered: Nov 11 2008
Posts: 37
Because when I reset the form it lost the Total hours worked. I had to go back to the the addition calucation of total hours worked. Check the fields again for it to give me the total hours worked for the month.

When I took out the "0" the total hours worked calculation stayed and gave me the total hours worked for that month.

To get my TPP hours per month I have them add up. That addition gives me TPP hours worked. I then have company hours and that adds up.

Those two added give me total hours worked. Making the field "Total Hours
Worked".

Giving me: Totall TPP Hours/Total Hours Worked = Percentage
jaynefergs
Registered: Nov 11 2008
Posts: 37
George tired it and it gave me: missing before statement 3 at line 4

var v1 = getField("Total TPP Hours").value;
var v2 = getField("Total Hours Worked").value;
Perform calculation and set this field value if total hours not zero
if (v2 != 0) { (it was highlighted here)
event.value = v1 / v2;
} else {
event.value = 0; // else force the result to zero
}
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The comment line is missing the two slashes that were in the original:

var v1 = getField("Total TPP Hours").value;var v2 = getField("Total Hours Worked").value; // Perform calculation and set this field value if total hours not zeroif (v2 != 0) { event.value = v1 / v2; } else { event.value = 0; // else force the result to zero }

George
jaynefergs
Registered: Nov 11 2008
Posts: 37
This worked! But for some reason the total company hours doesn't add up correctly. It really doesn't have anything to do with what I need. Because I really only need the percentage of TPP hours worked.

Total company hours, isnt' part of the calculation just the needed to get total hours worked. I guess I can take total company hours off the form.

Any suggestion........or should I leave well enought alone :) Thanks again for all your great help!!! Jayne
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
I would try to fix it. It could be that the field calculation order is incorrect or the calculation is not set up correctly.

George
jaynefergs
Registered: Nov 11 2008
Posts: 37
What should be the order.
Total TPPWorked
Total Hours Worked
Percentage

Because I have each column totaling down and across and the company hours are not part of the above calculation. Only in that it is included to give me Total hours worked.

Sorry for all these questions. Jayne
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You need to make sure that any value you need for a calculation has been updated prior to its value being used.

For you situation, you need to have both the "Total TPPWorked" and the "Total Hours Worked" before computing the "Percentage". Now the exact order may depend upon how the "Total TPPWorked" and "Totlal Hours Worked" are computed.

Another solution would be to perform all the calculations in one field and ass the values of the "Total TPPWorked" and "Total Hours" are computed those fields would be updated and the values computed would be used to compute the "Percentage" and fil in that field.

George Kaiser

jaynefergs
Registered: Nov 11 2008
Posts: 37
It is working. I went through the calculation order and now everything is working perfectly! I am so grateful for all your help and can't say enough about the extra mile you went in helping me. Jayne