Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

How do I populate a text box after selecting from a dropdown?

Avatar

Former Community Member

I am creating a form that has a dropdown with different types of products listed. After a person selects a product from the menu I would like to populate the text box with a description of the product.  I am a beginner here but I thought their was away to use JavaScript to do this. But wasn't exactly sure where to put the code and do I put it on the text box or the dropdown. Any help would be appreciated Ive been looking all over for a week and can find an answer.

1 Accepted Solution

Avatar

Correct answer by
Level 6

if (xfa.event.newText=="   ")
{TextField1.rawValue=""}

Place on your drop list using Java Script on the *change event"

If you had three items in your list:

A

B

C

if (xfa.event.newText=="A")
{TextField1.rawValue="You chose the letter A"}

if (xfa.event.newText=="B")
{TextField1.rawValue="You chose the letter B"}

if (xfa.event.newText=="C")
{TextField1.rawValue="You chose the letter C"}

View solution in original post

3 Replies

Avatar

Correct answer by
Level 6

if (xfa.event.newText=="   ")
{TextField1.rawValue=""}

Place on your drop list using Java Script on the *change event"

If you had three items in your list:

A

B

C

if (xfa.event.newText=="A")
{TextField1.rawValue="You chose the letter A"}

if (xfa.event.newText=="B")
{TextField1.rawValue="You chose the letter B"}

if (xfa.event.newText=="C")
{TextField1.rawValue="You chose the letter C"}

Avatar

Level 2

I would place the javascript code to change the value of the text box in then change event of the dropdown.  The code would look something like this.

if(this.rawValue == "Item 1")

     textBox.rawValue = "description 1";

If you didn't want to use an if statement you could use a switch statement then the code would look like this.

switch(this.rawValue)
{
case "Item 1":
  textBox.rawValue = "description 1";

  break;
case "Item 2":
  textBox.rawValue = "description 2";
  break;
default:
  textBox.rawValue = "";
}

I hope this helps.

DG

Avatar

Former Community Member

Thanks paulk07 so much that worked perfectly.