Copy link to clipboard
Copied
I have a form that I need three different Simplified Field Notations. How do I do that?
Use this code:
var a = Number(this.getField("M1").valueAsString);
var b = Number(this.getField("T1").valueAsString);
var c = Number(this.getField("A1").valueAsString);
if (c!= 0) {
event.value=(a+b)/c;
} else {
event.value = "";
}
Copy link to clipboard
Copied
For different fields? Just apply each calculation differently. It shouldn't be a problem.
Copy link to clipboard
Copied
I tried but it keeps writing over the first one.
Copy link to clipboard
Copied
Did you copy and paste the field? If so, you need to rename the copies so they have a unique name. Otherwise, they will remain exact copies of each other.
Copy link to clipboard
Copied
These are the two different ones. Does Locking the field make a difference?
Copy link to clipboard
Copied
No, it's only preventing you from editing it...
Those screenshots don't show that the fields are actually named differently.
Copy link to clipboard
Copied
The fields being:
Mealevent2 + tipevent2/AttendeesEvent2 This being the first Scripts
and
Refreshments+tip/Ateendees this being the second Script.
Are these not different enough?
Copy link to clipboard
Copied
Can you share the file in question (via Dropbox, for example)?
On Wed, Oct 4, 2017 at 12:09 AM, beverlyh81967728 <forums_noreply@adobe.com>
Copy link to clipboard
Copied
Those are the calculations, not the names. What are the names?
Copy link to clipboard
Copied
Those are the names of the fields.
Copy link to clipboard
Copied
Maybe that's the problem. Try giving them normal names (letters and numbers only)
Copy link to clipboard
Copied
Will do. Let you know tomorrow if it makes any difference. Thank you for your help.
Copy link to clipboard
Copied
Well that worked but now I'm getting the Java script error that the value entered does not match the field that has the division in it. From what I've seen on the web if the field is blank or 0 I'm going to get this error unless I can write a custom calculation script. Have you done that? I just need field 1 ("M1") + field 2 ("T1") / field 3 ("A1")
Copy link to clipboard
Copied
This happens when you try to divide by zero (or an empty value). You can't
use the Simple Field Notation if that's the case. You must write a custom
calculation script.
On Wed, Oct 4, 2017 at 8:04 PM, beverlyh81967728 <forums_noreply@adobe.com>
Copy link to clipboard
Copied
Can you help with that? I saw on another post one that you worked on but of course it doesn't work specially with mine. I'm close but it doesn't pick up the two fields needing to be added before the division.
var a =this.getField("M1");
var b =this.getField("T1");
var c =this.getField("A1");
if(a.value != 0)
{
// perform division;
event.value=((a.value+b.value)/(c.value))
} else {
// do not divide by zero;
event.value = "";
}
Copy link to clipboard
Copied
You're almost there, you're just checking the wrong variable... It's "c" that must not be zero, not "a".
Copy link to clipboard
Copied
I made that change but it's still not calculating correcting.
Attendees (A1)=2
Meals (M1)=100.00
tip(T1)=5.00
Cost per person=502.50 should be 52.50
The formula works if I take out the tip.
Copy link to clipboard
Copied
Use this code:
var a = Number(this.getField("M1").valueAsString);
var b = Number(this.getField("T1").valueAsString);
var c = Number(this.getField("A1").valueAsString);
if (c!= 0) {
event.value=(a+b)/c;
} else {
event.value = "";
}
Copy link to clipboard
Copied
Yes!! That worked. You are amazing! OK why didn't the other one work?
Copy link to clipboard
Copied
Because you didn't explicitly converting the values to numbers (as I did), they were being treated as strings and concatenated, instead of added up.
Copy link to clipboard
Copied
Thank You, Thank You!. One little field cost me a full day but with your help made it all worth it. Thanks again.