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

How to have one field calculate its value depending on the selection of a dropdown?

New Here ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

I am trying to figure out the correct Javascript to accomplish a certain action within my Adobe PDF. Here's a quick summary:

Field 1 is a dropdown menu containing 2 options. These options are "Arlington" and "Beverly Hills"

Field 2 needs to populate with the value of 1000 if Arlington is selected or a value of 1500 if Beverly Hills is selected

Can anyone help me with creating the javascript for this?

Thank you,

Matt

TOPICS
Acrobat SDK and JavaScript

Views

494

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jun 14, 2019 Jun 14, 2019

Ah, OK, then you can use something like this:

var v = this.getField("Field 1").valueAsString;

if (v=="Arlington") event.value = 1000;

else if (v=="Beverly Hills") event.value = 1500; // etc.

else event.value = "";

Votes

Translate

Translate
Community Expert ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

Apply those values as the export values of the items in the drop-down field and then use this code as the custom calculation script of the text field:

event.value = this.getField("Dropdown1").value;

Replace "Dropdown1" with the actual field name, of course.

Votes

Translate

Translate

Report

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
New Here ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

So I may have made my question too simple. I will actually have Field 2, Field 3, and Field 4 populating with their own unique value based on the selection made in Field 1. So I don't believe a single export value will work in this case.

Here's an example of my final product:

Field 1: Arlington

Field 2: Populates with 1000 because Arlington was selected

Field 3: Populates with 1200 because Arlington was selected

Field 4: Populates with 1400 because Arlington was selected

Fields 2-4 would populate with different values if Beverly Hills is selected.

In case it matters my dropdown menu actually has about 20 options and each option will need to populate fields 2-4 differently. I figured if I can get it working with just 2 options then I could figure out how to expand it to cover more options.

Votes

Translate

Translate

Report

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 ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

Ah, OK, then you can use something like this:

var v = this.getField("Field 1").valueAsString;

if (v=="Arlington") event.value = 1000;

else if (v=="Beverly Hills") event.value = 1500; // etc.

else event.value = "";

Votes

Translate

Translate

Report

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
New Here ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

LATEST

This worked perfectly, thank you so much for your assistance try67! You're awesome!

Matt

Votes

Translate

Translate

Report

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