Skip to main content
September 14, 2016
Answered

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

  • September 14, 2016
  • 2 replies
  • 1444 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 the drop down menu in "State," "OH Fund Center" will auto-populate with APWSWR4949 and "OH WBS" will auto-populate with WR49.73.0003.

I have a similar script for text fields a little bit lower in the form, but that script is not working.  I was trying the following script:

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

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

else event.value = "";

However, it would not auto-populate the OH Fund Center Box.  And I have no idea how to populate both fields at the same time.

Any help would be greatly appreciated.

Thank you!

Crystal

This topic has been closed for replies.
Correct answer try67

Strings needs to be placed between quotes. So change your code to:

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

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

else event.value = "";

If that works then you can use a similar code for your other field.

2 replies

September 30, 2016

I have been working with this, and it is back to not working.  I'm tried removing all of the script and doing it again, but still no luck.  I'm not sure what I am doing wrong.  It was working until I tried adding the second auto-population.

Suggestions?

Thanks!

try67
Community Expert
Community Expert
September 30, 2016

Can you post your new code? Are there any error messages in the JS Console when you run it?

September 30, 2016

Here is the new code:

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

How do I run the JS Console?

Thanks!

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 14, 2016

Strings needs to be placed between quotes. So change your code to:

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

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

else event.value = "";

If that works then you can use a similar code for your other field.

September 14, 2016

It worked!  Thank you!