Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Autopopulate multiple fields from drop-down list

Avatar

Level 1

Hi, I not too well versed in scripting for LiveCycle but great about getting other peoples scripts to do what I need.

Currently I have a form which I use that staff fill out when they want a new account to be created.

I have a State (drpState) which populates an Office (drpBranch) drop-down list via an Array script, so if they choose a state it will only show offices we have in those states.

I would like this user selection to populate other fields I have which are:

Street Address (txtStreet)

PO Box (txtPO)

Post Code (txtPCode)

Phone (txtPhone)

Fax (txtFax)

Which relate specifically to the office selected.

But I can't seem to find any script that would do something like that.

Can someone please assist?

Please note I'm very happy to redo the current scripts and such if the Array script I'm currently using can't get the job done.

The amount of work this will same me if it works properly would be worth it

Thank you

Dianne

4 Replies

Avatar

Level 10

Hi Dianne,

I gather there is no server side processing that populates your form, that is if there is a new office you have to send out a new form.  If so then you can do a similar thing with properties of an object as with an array.  So;

var States ="New South Wales"               : {},

                "Victoria"                      : {},

                "Queensland"                    : {},

                "South Australia"               : {},

                "Western Australia"             : {},

                "Tasmania"                      : {},

                "Australian Capital Territory"  : {},

                "Northern Territory"            : {}, };

Could be loaded with this code;

var listitems = [];

for (var state in Data.States)

{

    listitems.push(state);

}

this.setItems(listitems.join(","));

The advantage of using an object is that you can build up the structure of your data, so you could end up with;

var States = {

                "New South Wales":

                {

                    "Woolloomooloo" :

                    {

                        StreetAddress : "43-51 Cowper Wharf Road",

                        POBox : "P.O. Box 1",

                        PostCode : "2601",

                        Phone : "(02) 1111 2222",

                        Fax : "(02) 1111 3333"

                    },

                    "Surry Hills" :

                    {

                        StreetAddress : "415 Bourke Street",

                        POBox : "P.O. Box 2",

                        PostCode : "2010",

                        Phone : "(02) 2222 2222",

                        Fax : "(02) 2222 3333"

                    },

          etc

If this sounds like what you are after then have a look at this sample, the code is in the preOpen event of the drop down list and the change event of the offices drop down list.

https://workspaces.acrobat.com/?d=x5Xe-BQcDrve7GophYPuAQ

Hope that helps.

Bruce

Avatar

Former Community Member

Hi Bruce

I am tring to get my head around arrays and am looking for example forms / JS that I can decipher and reuse (basically steal! )

My task is to build a form that is 'preloaded' with information (possibly an array?) - an initial dropdown is prepopulated with the values from the first 'column' of the array . Once a user selects a value (Eg 'Surry Hills') the cooresponding information is then sent to various text boxes (Eg '415 Bourke Street' , 'PO Box 2' etc). (The array would normally have around 200 lines of info however occasionally could hit 2000 region)

This thread seems to address a similar issue however the sample URL seems to be dead (probably because its 2 years old! )

Do you still have the sample - would it be possible to re-upload please?

Many thanks

Ellis

Avatar

Former Community Member

Good on yer Bruce !

The form was all I hoped it was - perfect thanks!

You just made my life a lot easier - cheers !

E