Skip to main content
September 30, 2016
Question

How to populate two text fields based on a single drop down list selection

  • September 30, 2016
  • 1 reply
  • 635 views

I'm trying to set up a form so that two text fields will populate with a default text (separate text in each text field) at the same time.

Below is a screenshot of the fields.

So, for example, if I select Utah (from 14 options) from the drop down menu in "State," "OH Fund Center" will auto-populate with APWSWR4949 and "OH WBS" will auto-populate with FR49.73.

Here is the script I have been using in the Calculate tab in Properties for the OH Fund Center box:

var v1 = this.getField("RecState").valueAsString; 

if (v1=="Colorado") event.value = "APWSWR0808"; 

if (v1=="Idaho") event.value = "APWSWR1616";

if (v1=="Montana") event.value = "APWSWR3030";

if (v1=="Nebraska") event.value = "APWSWR3131";

if (v1=="Nevada") event.value = "APWSWR3232";

if (v1=="New Mexico") event.value = "APWSWR3535";

if (v1=="Oklahoma") event.value = "APWSWR4040";

if (v1=="Oregon") event.value = "APWSWR4141";

if (v1=="South Dakota") event.value = "APWSWR4646";

if (v1=="Tennessee") event.value = "APWSWR4747";

if (v1=="Texas") event.value = "APWSWR4848";

if (v1=="Utah") event.value = "APWSWR4949";

if (v1=="Washington") event.value = "APWSWR5353";

if (v1=="Wyoming") event.value = "APWSWR5353";

else event.value = "";

It is not working.   I'm at a loss on getting this to work, before I can figure out auto-populating the OH WBS box.

Also, I need both the OH Fund Center and OH WBS boxes to clear/change if a new state is selected.

 

Any help would be greatly appreciated.

Thanks.

Crystal

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
September 30, 2016

Your else command only applies to the last if-condition, rendering the rest of them moot.

You should use this structure:

if () ...

else if () ...

else if () ...

else ...

September 30, 2016

Oh, gosh.  Yes, it worked now.  And I got the second auto-pop box to work too.

Thank you!

May 3, 2017

Hello,

I am attempting to populate a text-field based on a conditional dropdown. For ex. dropdown 1 has 3 levels...when level 5 is chosen, this populates week 1,2,3,4 in dropdown2. When level 6 is chosen, this populates week 1, 2, 3, 4 in dropdown 2 and so forth. I got the two dropdowns working, however I would like a specific text to populate in Text1 when level 6 (dropdown1), week 2 (dropdown2) is chosen. How can I do this?