Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Javascript for populating text field based on dropdown list

Avatar

Former Community Member

Hi,

I am trying to write a javascript to populate a "Textfield" based on what I select on a "Dropdownlist" this has a one on one relationship with each other. I tried to embed the script on "Change" category and the script was as follows but it did not work. I'd appreciate if someone can help me with the correct procedure.

Thanks,

Vijay

form1.#subform[0].DropDownList2[0]::change - (JavaScript, both)

function populateDescription(){

        if (document.subform[0].DropDownList2[0].value=="BIH"){

                    document.subform[0].TextField83[0].value="Burn in and PBI History";

        }

}

1 Accepted Solution

Avatar

Correct answer by
Level 3

I solved this same issue by using a switch script.

Please see my earlier thread regarding this and Paul's example will provide you with the proper scripting for a switch script.

http://forums.adobe.com/thread/479021

script on the drop down list as follows

switch (this.rawValue) {

     case "dropchoice1"

          fieldname1.rawValue = "text choice here";

          fieldname2.rawValue = "text choice here";

          break;

     case "dropchoice2"

          fieldname1.rawValue = "text choice here";

          fieldname2.rawValue = "text choice here";

          break;

}

Good luck.

View solution in original post

8 Replies

Avatar

Level 7

First, put your script on the click event of the drop down list rather than the change event. After that, try:

if (document.subform[0].DropDownList2[0].rawValue=="BIH"){

                    document.subform[0].TextField83[0].rawValue="Burn in and PBI History";

        }

To shorten up your script a bit, you can also use:

if this.rawValue=="BIH"){

                    document.subform[0].TextField83[0].rawValue="Burn in and PBI History";

        }

Avatar

Former Community Member

Thanks a lot. I tried both and still wouldn't work

Avatar

Level 7

Post a sample of your form and I'll try to get it working for you.

Avatar

Former Community Member

Here's the sample... I want to populate the text field based on the selection on Drop down

BIH           BURN IN & PBI HISTORY

FST          FUNCTIONAL STRUCTURE TEST

MARKV    MARK VERIFICATION

Thanks much.

Vijay

Avatar

Correct answer by
Level 3

I solved this same issue by using a switch script.

Please see my earlier thread regarding this and Paul's example will provide you with the proper scripting for a switch script.

http://forums.adobe.com/thread/479021

script on the drop down list as follows

switch (this.rawValue) {

     case "dropchoice1"

          fieldname1.rawValue = "text choice here";

          fieldname2.rawValue = "text choice here";

          break;

     case "dropchoice2"

          fieldname1.rawValue = "text choice here";

          fieldname2.rawValue = "text choice here";

          break;

}

Good luck.

Avatar

Former Community Member

That's exactly what I wanted... it worked perfectly.

Thank you very much both of you.

Vijay

Avatar

Level 2

I need to have a field auto-populate from three previous selections.  Would this work for that?  I am going to try and write it out below.  I am sure the code will be wrong, but you get the idea (I hope!)

if Species.rawValue=="Human" AND Gender.rawValue=="Female" AND RefType.rawValue=="Standard"){

                    SampleRef.rawValue="Human";

        }

Thanks for your help.  Anne

Avatar

Level 2

Well, I figured it out and this works, so I will post it here in case anyone else has the same problem. 

if (Species.rawValue=="Human" & Gender.rawValue=="Female" & RefType.rawValue=="Standard"){

                    SampleRef.rawValue="HumanNCB137_XX";

        }

       

if (Species.rawValue=="Human" & Gender.rawValue=="Male" & RefType.rawValue=="Standard"){

                    SampleRef.rawValue="HumanNCB137_XY";

        }

if (Species.rawValue=="Human" & Gender.rawValue=="Unknown" & RefType.rawValue=="Standard"){

                    SampleRef.rawValue="Human";

        }

if (Species.rawValue=="Human" & RefType.rawValue=="Custom"){

                    SampleRef.rawValue="HumanNCB137_XY";

        }