Page 1 of 1

How to use drop-down to add data to form

Posted: Wed Feb 23, 2022 4:57 am
by msbask99
We're creating a form with a drop-down containing several kinds of fruits. Based on what the user selects, we'd like to have the price automatically put on the form.

Image

Is there a way to do this?

Re: How to use drop-down to add data to form  SOLVED

Posted: Wed Feb 23, 2022 4:54 pm
by Paul - PDF-XChange
Hi msbask99

JavaScript required for this, and there are different ways to do it.

The simplest way can be used if the price is not to be be modified by the user. In this case you need to add a calculation script for that Price field, and in this script you need to get the selected item and return corresponding price (please note, return value is set via event.value):

Code: Select all

var idx = getField("Fruit").currentValueIndices;
if (idx == 0)
  event.value = 10.0;
else if (idx == 1)
  event.value = 20.0;
if the price can be modified by the user, Keystore event for the Fruit field should be used. And the code will be different

Code: Select all

if (!event.willCommit)
  return;
var price = 0;
if (event.value = "Oranges")
  price = 10.0;
else if (event.value = "Apples")
 price = 20.0;
...
if (price > 0)
  getField("Price").value = price;

Does that help? Can you take it from there?

Re: How to use drop-down to add data to form

Posted: Wed Mar 02, 2022 2:00 am
by msbask99
Paul - Tracker Supp wrote: Wed Feb 23, 2022 4:54 pm Does that help? Can you take it from there?
Yes, that helps, thanks!

How to use drop-down to add data to form

Posted: Wed Mar 02, 2022 10:08 am
by Dimitar - PDF-XChange
:)