Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


How To Populate Text Field When A Drop Down List Item From Another Field Is Selected

New Here ,
Sep 05, 2021 Sep 05, 2021

Copy link to clipboard

Copied

Hi
I ask you if, please, someone can solve this question for me.
How to Populate text field (eg "A") when A Drop Down List Item From Another Field Is Selected (eg "B") by copying the contents of another text field (eg "C"). The text fields "A" and "C" are not drop-down menus.
I would like to insert the formula in the drop down "B".
I found this formula
switch (event.value)
{case "x": this.getField ("y"). setItems (["1,2,3,4"]); break;
I was unable to adapt it to the function I need.
Please, anyone who can help me?

TOPICS
JavaScript

Views

93

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Sep 05, 2021 Sep 05, 2021

Copy link to clipboard

Copied

From my understanding you want to populate text field "A" with value from text field "C" if certain value in dropdown "B" is selected, first of the script you provided is to set items into dropdown fields so that is not what you asking for.

Here is script to populate field "A", use it in dropdown field as 'validation' script:

if(event.value == "value1")
this.getField("A").value = this.getField("C").value;

 

You can add:

else this.getField("A").value = "";

to the bottom of the script if you wish to empty field "A" if some other item is selected in dropdown.

Change "value1" to the actual value you have in dropdown and tick 'commit selected value immediately' in dropdown field->options tab.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 05, 2021 Sep 05, 2021

Copy link to clipboard

Copied

Hi
Thank you for your reply.
I followed your instructions, but it doesn't work.
This is the script I placed in the drop-down menu validation script
if (event.value == "A")
this.getField ("A"). value = this.getField ("C"). value;

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Sep 05, 2021 Sep 05, 2021

Copy link to clipboard

Copied

This code should work.

What exactly happen when you use it?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 05, 2021 Sep 05, 2021

Copy link to clipboard

Copied

Hi
I have tried this feature
var f = this.getField ("A");
if (f.valueAsString == "A") {this.getField ("A"). value = this.getField ("C"). value;}
In the drop-down menu I have entered the letters "A" and "B". I have flagged all the options in the "options" tab.
When I select the letter "A" nothing happens, while when I select the letter "B", the value entered in the "C" text field appears in the "A" text field.
Please, is anyone kind enough to explain to me why this happens?
Thanks

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 05, 2021 Sep 05, 2021

Copy link to clipboard

Copied

Hi
I have tried this feature
var f = this.getField ("E");
if (f.valueAsString == "A") {this.getField ("A"). value = this.getField ("C"). value;}
In the drop-down menu I have entered the letters "A" and "B". I have flagged all the options in the "options" tab.
When I select the letter "A" nothing happens, while when I select the letter "B", the value entered in the "C" text field appears in the "A" text field.
Please, is anyone kind enough to explain to me why this happens?
Thanks

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Sep 05, 2021 Sep 05, 2021

Copy link to clipboard

Copied

Where exactly did you place the code? Under which event?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 05, 2021 Sep 05, 2021

Copy link to clipboard

Copied

I placed the code in the "E" drop-down menu custom validation script

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Sep 05, 2021 Sep 05, 2021

Copy link to clipboard

Copied

OK, then to access the newly selected value you must use event.value, not this.getField("E").valueAsString.

That will return the field's current (ie. old) value, as the new one hasn't been approved yet by the validation event.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 05, 2021 Sep 05, 2021

Copy link to clipboard

Copied

hi
I changed the formula like this
var f = this.getField ("E");
if (f.value == "A") {this.getField ("A"). value = this.getField ("C"). value;}
The result does not change. When I select the letter "A" from the drop-down menu, nothing happens. When I select the letter "B", the contents of the "C" text field appear in the "A" text field.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

 

EDIT:

Can you try this code:

if(event.value == "A")this.getField("A").value = this.getField("C").value;

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

Thank you very much. The formula works

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Sep 06, 2021 Sep 06, 2021

Copy link to clipboard

Copied

That's not what I suggested. Read my reply again.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied

LATEST

Many thanks for the help. Problem solved

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines