Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Populate a price field based on the product selected in dropdown field

Community Beginner ,
Apr 05, 2018 Apr 05, 2018

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

ProductTable.jpg

TOPICS
PDF forms
4.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2018 Apr 05, 2018

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.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 06, 2018 Apr 06, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2018 Apr 06, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 06, 2018 Apr 06, 2018

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

dropdownlist.jpgProductTable.jpg

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2018 Apr 07, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2018 Apr 07, 2018

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.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 12, 2018 Apr 12, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2018 Apr 13, 2018
LATEST

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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines