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

IF/THEN js help for forms

thedonat
Registered: Jul 6 2010
Posts: 10
Answered

hello

It's probably super simple but I'm a total novice with acrobat forms.

what I have so far to show the shipping cost is:

var f = this.getField("SubTotal");
event.value = Math.max(7, Math.floor(f.value * 0.1));

so I have a minimum of $7 and for the rest it's 10% of the subtotal
and that works fine

BUT

I need to add a way if it the subtotal is more than $250 that the shipping shows the word "FREE"

I know this is wrong but just to show what I'm trying to get to:

var f = this.getField("SubTotal");
if (SubTotal == >250)
event.value = 'FREE';
else
event.value = Math.max(7, Math.floor(f.value * 0.1));

thank you for your time

My Product Information:
Acrobat Pro 9.3.1, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
This is wrong:
if (SubTotal == >250)Use this:
if (SubTotal >= 250)

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

thedonat
Registered: Jul 6 2010
Posts: 10
thanks Try

though not working still

I have:

var f = this.getField("SubTotal");
if (SubTotal >= 250)
event.value = 'FREE';
else
event.value = Math.max(7, Math.floor(f.value * 0.1));

that's just leaving my SHIPPING field blank

when I have

var f = this.getField("SubTotal");
event.value = Math.max(7, Math.floor(f.value * 0.1));

then I have a value that shows up in the SHIPPING field.
but of course it's not correct if the subtotal is more than $250

any idea what's causing that?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You're not defining the variable SubTotal anywhere.
It should be:
var f = this.getField("SubTotal");var SubTotal = f.value;if (SubTotal >= 250)event.value = 'FREE';elseevent.value = Math.max(7, Math.floor(SubTotal * 0.1));

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

thedonat
Registered: Jul 6 2010
Posts: 10
thanks

it accepted that code but
now I get this error message:

The value entered does not match the format of the field [ SHIPPING ]

when I have entered orders over $250
try67
Expert
Registered: Oct 30 2008
Posts: 2398
If you set the field to be formatted as a number, then you can't set its value to a string.
I suggest using no Format at all.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Numerically formatted values are not Alphanumeric string text, they are floating point numbers and are formatted very differently and are not compatible.

You can not set a field with a numeric format to the text 'FREE'.

But you can place a number in a text field as a text string. But that can cause other problems if you want to access the numeric value of that field in a numeric calculation elsewhere.

George Kaiser

thedonat
Registered: Jul 6 2010
Posts: 10
thank you try and gkaiseril

it's solved!!

awesome!!