Copy link to clipboard
Copied
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
2 Correct answers
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
...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 = "";
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Asim123 script just for the price
Copy link to clipboard
Copied
@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
Copy link to clipboard
Copied
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 = "";

