Copy link to clipboard
Copied
I will have about 10 product dropdown fields with the ability to pick from about 50 products. Then based on the product chosen I need to populate the price field with that product price. Then multiply the price by the Quantity to get a total for all products. I don't know how to write the scripts but I can figure them out with anyones help. I have searched the forum and found some similar questions but not exactly like mine so far. The attached picture shows my actual table. I'm using Acrobat XI

Copy link to clipboard
Copied
See theses article:
https://acrobatusers.com/tutorials/change_another_field
https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations
Free Sample PDF Files with scripts
Calculating field values and more
the first one explains how to set fields with a dropdown. The next one explains how to do calculations. The next one is a page of sample files. The last one is a calculation example. The last link is to a page that covers some of the basics for doing calculations. It also has links to much more detailed articles and samples on performing different types of calculations, but these can only be accessed by members.
Copy link to clipboard
Copied
Thanks again for the reply. Would it make a difference if I have the list of corresponding prices for each product? Or would it be useful to have the price included in the list of products so when you choose the dropdown product the price is included in that line? In my excel spreadsheet, I am able to have the price field pull from the corresponding price cell in the price list. Hopefully, that makes sense.
Copy link to clipboard
Copied
You should include the price as the export value of each product in the drop-down. If you do that the rest is really simple.
You would then just need a simple calculation script to copy the value of the drop-down to the price field, and then a simple product formula (not even a script) to multiply the price by the quantity and get the total.
The grand total is also just a simple sum formula of all the total fields.
Copy link to clipboard
Copied
Thanks, I'm not sure what you mean "include the price as the export value of each product in the drop-down" Here is what my dropdown list looks like


So are you saying that I should load the data into the dropdown field with the price included with the data. I'm not sure how you would then strip the price from the selection to populate the price field. Sorry, scripts and programming just ain't my thing.
Copy link to clipboard
Copied
When you add items to a drop-down in Acrobat there are two text fields you can use: Item and Export Value.
The first is what the user sees and is mandatory. The second is the actual value selected, and is optional. If you omit it, the value is the same as the display value. But if you specify it will become the underlying value of the field when that option is selected.
So in this instance I'm adding a product with a price of "100" (I do not include the currency symbol, so it remains a pure number):

In the price text field I can then use the following code as the custom calculation script:
event.value = this.getField("Product").valueAsString;
(assuming "Product1" is the name of the drop-down field)
The price of the selected product will then appear in this field when a selection is made in the drop-down.
Copy link to clipboard
Copied
I would advise a different strategy, i.e., the strategy outlined in the first link in my previous post. Export values are convenient, but need to be unique, and prices are not necessarily unique.
Copy link to clipboard
Copied
Thom,
I know this is a lot to ask but would it be possible to show me an example of a script using my data so I can see how it would actually work. Also, is there anywhere that I can learn this scripting language.
Copy link to clipboard
Copied
Have you looked at the links I posted? I think they pretty much cover most of what you need.
You can learn about the Core JavaScript language here:JavaScript | MDN
An excellent place to learn about Acrobat JavaScript is pdfscripting.com
And of course you should also have the Acrobat JavaScript Reference: Acrobat DC SDK Documentation
Find more inspiration, events, and resources on the new Adobe Community
Explore Now