Skip to main content
Participant
October 30, 2018
Question

If/then statement on .PDF form

  • October 30, 2018
  • 1 reply
  • 1320 views

I have an order form that has only one product. I need to run a simple if/then script that automatically populates another field (price).

It is basically; if you buy 1 of the product it is: $100 per item. If you buy 2+ items, it is $90 per item.
The user then populates how many items they would like (logic is displayed above), it then automatically populates their price in the next field. (Total).

Having a bit of an issue finding the correct code, seems easy enough, but having a bit of trouble.
Any help would be greatly appreciated.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
October 30, 2018

As the calculation script of the price field use something like this:

var qty = Number(this.getField("Quantity").valueAsString);

if (qty==0) event.value = "";

else if (qty==1) event.value = 100;

else if (qty>=2) event.value = 90;

afettlingAuthor
Participant
October 30, 2018

Okay, so is this placed with the Total Field?

For instance, you have two fields, 1 for the total number of products (Quantity), then the other is where the price will be automatically displayed (Total).

I have just pasted this into Total but nothing happens.

Thanks for your reply.

try67
Community Expert
Community Expert
October 30, 2018

Yes, the total field. Make sure you enter the exact name of the quantity

field as it appears in your form in the first line of the code.

After you enter the script edit the value of the quantity field and if it's

not working press Ctrl+J and check if there are any error messages in the

Console window that opens.