Copy link to clipboard
Copied
Hi!
I'm using Adobe Acrobat Standard and I'm trying to write a custom calculation script but I'm missing something which is causing a wrong value to return.
This is the calculation script:
var v1 = 1 * this.getField("FIELD23").value;
var v2 = 1 * this.getField("FIELD32").value;
var v3 = 1 * this.getField("FIELD33").value;
var v4 = 1 * this.getField("FIELD42").value;
var v5 = 1 * this.getField("FIELD43").value;
var v6 = 1 * this.getField("FIELD34").value;
event.value = [(v3 * v1) * (v2)] + [(v5 * v1) * (v4)] + [(v6) * (v2 + v4)]
This is what the variables equal:
v1 = 60%
v2 = 8
v3 = $20
v4 = 8
v5 = $30
v6 = $5
It needs to calculate as follows:
20 (v3) x 60% (v1) = $12 * 8 (v2) = $96 +
30 (v5) * 60% (v1) = $18 * 8 (v4) = $144 +
5 (v6) * 8 (v2) + 8 (v4) = $80
The total should be $320 but I keep getting $9,614,480.
Can anyone help me please, please, please (before all the hair on my head is gone)? Where am I going wrong?
Thank you so much!!
Diane
Copy link to clipboard
Copied
Remove all the square brackets from the last line. Use only round ones.
Copy link to clipboard
Copied
Remove all the square brackets from the last line. Use only round ones.
Copy link to clipboard
Copied
YOU are AMAZING, try67, again my hero!! Thank you so much!! 🙂 I kept shuffling the bracketed numbers around but completely spaced on the brackets themselves.
Thank you thank you thank you! And my scalp thanks you as well! 😉
Have a terrific evening!
Diane
Copy link to clipboard
Copied
Edit:
Hi! I got it worked out!
I formatted the field FIELD23 as a number with zero decimals.
I then entered the following in the custom validation script box for FIELD23:
var f = this.getField("FIELD23");
f.hidden = (event.value > 99);
I then found that when the end user enters 100 and the field goes to hidden the user then can't access it should they have accidentally entered 100 and need to change it to a lower number.
So then I created a button that is supposed to "show/hide" FIELD23. I can make it show FIELD23 after the user has entered 100 and the field has gone hidden, so that the 100 can be changed if need be, but I can't make it rehide it should the user realize it should remain at 100.
I did find though that they can enter a different number in FIELD23 to replace the 100 and then TAB out of FIELD23 and then TAB back to FIELD23 and enter 100 and then TAB out again and FIELD23 will go hidden again.
I hope that makes sense. 🙂
Did I go about it in a convoluted manner or is there a better way?
Again, thank you so much!!
Diane
---
Hi!
Follow-up question... I'm sorry, I didn't realize this next issue would happen...
Sometimes the 60% (v1) will be 100%. So I deleted the 60% (thinking it would go blank so to speak and the calculation script would just ignore it, but instead it made it 0%) and now the final result of the calculation, which should be $480 now, is only $80. When I put 100% in there then it calculates accurately, $480.
The problem is that when the form is being used, the only time a percentage will be entered is when it's less than 100%. If it's 100% then the box doesn't get filled in.
I have other fields (not percentage, just numbers) that I've validated to remain hidden or blank when the value is less than .001.
This is the validation code I use for that:
var f = this.getField("FIELD98");
f.hidden = (event.value < .0000001);
Is it possible to set up the percentage field in such a way so that when it's 100% or greater it's hidden, the field appears blank? I'm assuming I can't set it up so that it recognizes a 0.00% or non-entry as actually being 100%.
Again, thank you so much for your time and generosity in sharing your skills and knowledge! I was thanked effusively today for helping someone earlier today and I want to pass that on to you - truly thank you so much. 🙂
Diane
Copy link to clipboard
Copied
> I'm assuming I can't set it up so that it recognizes a 0.00% or non-entry as actually being 100%.
Do you want to change the actual field's value, or just treat it as such in your calculation? Both are possible.
PS. You should not use the hidden property. It's outdated. Replace it with setting the display property as display.hidden. But I don't think that hiding the field is the correct solution for this issue.
Copy link to clipboard
Copied
Hi and Good Morning!
Thank you! 🙂
I'm not certain I understand your question so I'm going to try to answer; I apologize if I missed the mark. 🙂
I'm not worried about the field's value per se other than I need it to be hidden when it's 100, visible when it's less than 100, changeable should someone accidentally enter 100, and also work in the calculation.
I feel like I didn't provide any more info there than what I have prior and I apologize for that, I don't think I understand your question enough, I'm sorry.
Thank you for your PS as well. I'll have to work at wrapping my old brain around that next. 🙂
Diane