Skip to main content
Known Participant
April 1, 2023
Answered

Auto-populate text based on multiple dropdown selection

  • April 1, 2023
  • 1 reply
  • 1068 views

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 

This topic has been closed for replies.
Correct answer try67

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 = "";

1 reply

Nesa Nurani
Community Expert
Community Expert
April 1, 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;

try67
Community Expert
Community Expert
April 1, 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.

Inspiring
April 1, 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.