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

Auto-populate text based on multiple dropdown selection

Explorer ,
Apr 01, 2023 Apr 01, 2023

Hi guys, I don't know if that's possible or not because i am searching this for hours but in vain.

 

I have a text field "Price", and I need price to be populate based on 2 dropdown selections.

 

Dropdown 1: "Taste". Options: Sweet, Sour

Dependent Dropdown 2: "Fruits". Options for sweet are apple and banana. Option for sour are lemon and orange.

When sweet is selected, fruits give options as apple and banana and vice versa for sour.

 

So technically I have 2 different price list for sweet and sour. What i want is when:

1. sweet + apple is selected price will be $1.

2. sweet + banana selected, price $2.

3. sour + orange, $ 3

4. sour + lemon, $ 4.

 

Please help me, i am not a js expert. And i don't know if that's make sense. 

The example is just to understand 

TOPICS
Acrobat SDK and JavaScript
961
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

correct answers 2 Correct answers

Community Expert , Apr 01, 2023 Apr 01, 2023

You can use this as 'Validation' script of "Fruits" field:

var price = this.getField("Price");
if(event.value == "apple")
price.value = 1;
else if(event.value == "banana")
price.value = 2;
else if(event.value == "orange")
price.value = 3;
else if(event.value == "lemon")
price.value = 4;
else 
price.value = "";

It's case-sensitive, so be careful if you use banana or Banana...etc.

If you set items in "Fruits" with script, you could also set price to be export value and then just use this script in

...
Translate
Community Expert , Apr 03, 2023 Apr 03, 2023

Use this code as the custom Calculation script of the price field:

 

var fruit = this.getField("fruit").valueAsString;
var weight = this.getField("weight").valueAsString;

if (fruit=="apple" && weight=="1kg") event.value = "$1";
else if (fruit=="apple" && weight=="2kg") event.value = "$2";
 // etc.
else event.value = "";
Translate
Community Expert ,
Apr 01, 2023 Apr 01, 2023

You can use this as 'Validation' script of "Fruits" field:

var price = this.getField("Price");
if(event.value == "apple")
price.value = 1;
else if(event.value == "banana")
price.value = 2;
else if(event.value == "orange")
price.value = 3;
else if(event.value == "lemon")
price.value = 4;
else 
price.value = "";

It's case-sensitive, so be careful if you use banana or Banana...etc.

If you set items in "Fruits" with script, you could also set price to be export value and then just use this script instead:

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

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 01, 2023 Apr 01, 2023

You will also need to apply a similar script in the other drop-down, though. I think it makes more sense to use the Calculation event of the text field to show the combined value.

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
Enthusiast ,
Apr 01, 2023 Apr 01, 2023

For me, the question is confusing, I'm not sure if he's asking just for price script or also need script to populate the second dropdown.

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
Explorer ,
Apr 01, 2023 Apr 01, 2023

Asim123 script just for the price

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
Explorer ,
Apr 01, 2023 Apr 01, 2023

@Nesa Nurani I'm sorrryyyy my question was wrong :(((.

the scenario is:

dropdown 1: "fruit", apple and banana

dropdown 2: "weight", 1kg and 2kg

text field "price" = (auto-populate js?)

 

now the prices are:

apple + 1kg = $1

apple + 2kg = $2

banana + 1kg = $3

banana + 2kg = $4.

 

Soooo sorry for wrong question guys :(((. i messed up

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 03, 2023 Apr 03, 2023
LATEST

Use this code as the custom Calculation script of the price field:

 

var fruit = this.getField("fruit").valueAsString;
var weight = this.getField("weight").valueAsString;

if (fruit=="apple" && weight=="1kg") event.value = "$1";
else if (fruit=="apple" && weight=="2kg") event.value = "$2";
 // etc.
else event.value = "";
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