Skip to main content
Participating Frequently
April 18, 2022
Answered

Using a dropdown to prefill data

  • April 18, 2022
  • 1 reply
  • 520 views

I've seen numerous ways to do this, but I don't really know Javascript enough to get it to work.

 

Basically I have a form I'm creating that I want to autofill most of the data based on a dropdown menu.  I have the menu created.  It is called "Designation" with three possible choices, A, B, C.  I have a text box  below that, that I want to autopopulate with data based on the choices in Designation. 

 

If Designation = A, fill the text box with "123"

If Designation = B, fill the text box with "456"

If Designation = C, fill the text box with "789"

 

What would be the proper code for this, and will it fill based on clicking the dropdown and not a trigger with the text box?  

 

Thanks.

This topic has been closed for replies.
Correct answer Nesa Nurani

As 'Validation' script of dropdown field use this and change "Text1" to your actual text field name:

var txt = this.getField("Text1");
if(event.value == "A") txt.value = "123";
else if(event.value == "B") txt.value = "456";
else if(event.value == "C") txt.value = "789";
else txt.value = "";

 

Changing value in dropdown will trigger script.

In dropdown field properties under options tab check 'Commit selected value immediately'.

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
April 18, 2022

As 'Validation' script of dropdown field use this and change "Text1" to your actual text field name:

var txt = this.getField("Text1");
if(event.value == "A") txt.value = "123";
else if(event.value == "B") txt.value = "456";
else if(event.value == "C") txt.value = "789";
else txt.value = "";

 

Changing value in dropdown will trigger script.

In dropdown field properties under options tab check 'Commit selected value immediately'.