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

Need help with complicated form field computations...

buramiko
Registered: Mar 11 2009
Posts: 8

I'm creating a product order form and would like to apply a promotional discount to each order.
The discount will be "buy any 5 products and you get the lowest priced item free"
If buyer select 10 items then the 2 cheapest items amongst his selection will be free and so forth.
Say I have form fields for product name i.e. product1, product 2, etc. ; product price (which will be entered by me) i.e. price1, price2, etc. and purchase qty (entered by buyer) i.e. qty1, qty2, etc, how do I output :
1. The product name(s) of all free products based on buyer's selections?
2. The total price of the order after the discount?

Or is this even possible at all with acrobat javascript??

My Product Information:
Acrobat Pro 8.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Of course this is possible, it's not even that complex. The first part of the solution is identifying the two cheapest items. Do you mean total price (qty * price) or just price?

The way to do this is to loop through all entries and collect a list. Then sort the list
var saveStack = [];for(var i=1;i<nItems+1;i++){var price = this.getField("price"+i).value;if(price && !isNaN(price))saveStack.push({idx:i,pr:price});} // need custom sort function.saveStack.sort(function(A,B){return A.pr -B.pr;});

Now the two cheapest prices are at the top of the array, in index 0 and index 1. All the other info can be derived from this.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

buramiko
Registered: Mar 11 2009
Posts: 8
Hi Thom, thanks for your help.
Unfortunately I'm not very literate in javascript...so please provide a more detailed codes?

So when the code collects the list of prices, does it pick out ONLY the ones that the buyer has entered a qty to it (since there are items that the buyer isn't buying and qty fields will be blank)?

And say if a single item is purchased 2 qty, then the list will incorporate this item 2 times right? I presume this wold be necessary in identifying the cheapest items in the purchase list even though they could be identical.
And I don't see there are "qty" fields identified in your codes... is that not necessary?

Since I don't know javascript at all, can you please give more details as how to pick out the free items? i.e. after sorting the purchase list, need to output the 1 cheapest item if total purchase item is 5, or 2 cheapest items if total purchase item is 10, or 3 items if total purchase is 15 and so on.

And how shall I calculate the total price of the entire purchase list after discount?
i.e. (qty1 * price1) + (qty2 * price2) +.... MINUS the (qty * price) of the free items.

Your help is appreciated!!!!!!!!
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The script only collects the price fields that are filled in and non-zero. It then pushes the price, and it's line number into an array. It doesn't do anything with the other fields. But there is no reason it couldn't be modified to include the features you're asking about.

At this point I would suggest that you either learn a bit about Acrobat JavaScript (there are some excellent video tutorials at www.pdfscripting.com) , and/or hire a devloper/consultant.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script