Skip to main content
majkk21244367
Participant
May 14, 2019
Answered

ListBox autofill textfield from other elements in the form.

  • May 14, 2019
  • 1 reply
  • 526 views

Hi.

Complete beginner here and I have been trying to find information on the forum pertaining to my dilemma but have thus far been unsuccessful sadly. Im trying to get a ListBox to add a value into a Text Field depending on what is chosen in the listbox. The ListBox contains choices which represent values in other calculated Text Fields fields. For example, I have choices Bananas, Oranges and Apples in the List Box. What I want to appear in the chosen Text Field is the amount of fruit of the chosen fruit. This information has been calculated in 3 otherText Fields on the page called either BananasAmount, OrangesAmount and ApplesAmount. Do I only need to script the Text Field where I want the information to be put or do I need to prep the ListBox or the other 3 text fields in anyway?

My searches here have given me this which does not work but might be a beginning. I have entered this into the Calculate-> Custom Calculation Script:

var v = getField("ListBox").value;

if (v == Banana)

event.value = BananasAmount;

else (v == Orange)

event.value = OrangesAmount;

if (v == Apple)

event.value = ApplesAmount;

Thankful for any help!

This topic has been closed for replies.
Correct answer try67

Change this:

if (v == Banana)

event.value = BananasAmount;

To:

if (v == "Banana")

event.value = this.getField("BananasAmount").valueAsString;

And the same for all the rest, of course.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 14, 2019

Change this:

if (v == Banana)

event.value = BananasAmount;

To:

if (v == "Banana")

event.value = this.getField("BananasAmount").valueAsString;

And the same for all the rest, of course.

majkk21244367
Participant
May 15, 2019

Shazam it works! Thanks a lot try67!