Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Need help with Drop-Down List

Avatar

Former Community Member
Hi.



I'm creating a form and part of this form has a "Nominated Bank Details" section where a user can select his/her bank name from a drop-down list and the bank's address, SWIFT Code, account name and number will auto populate in it's own corresponding text field.



I've only managed to populate the bank's address using the Global binding. How do I do that with the rest of the fields?



The forms will be sent via email to our consultants to filled up and returned to us via the same method on a monthly basis.



Thanks for any help!
6 Replies

Avatar

Former Community Member
Hi Jamie,

What do you mean on "auto populate"?

Avatar

Former Community Member
Sorry, I'm a newbie and my terms may have gotten a little off.



What I'm hoping to acheive is when a user selects a bank from the drop down list, the bank's corresponding address, SWIFT code, account name and number will show up automatically in the four text fields below.

Avatar

Former Community Member
Hi Jamie,

Assuming that you know each bank's address and swift code and can define it statically, you can use the code below.



// -- bankScript begin

// Array of part banks or you can know the order of the banks.

var banks = new Array(" ",

"Bank1",

"Bank2");



// Array of bank addresses.

var bankAdd = new Array(null,

"Bank 1 Add",

"Bank 2 Address");



// Array of bank swift code.

var bankSwift = new Array(null,

"SF1",

"SF2");



function getBankInfo(bankName, bankAddField, bankSwiftCodeField)

{

var i;

for (i = 0; i < banks.length; i++) // Go through the entire list of banks to find the one that is currently selected.

{

if (banks[i] == bankName) // When find the bank currently selected.

{

bankAddField.rawValue = bankAdd[i]; // Put the address to the adress field

bankSwiftCodeField.rawValue = bankSwift[i]; // Put the swift code to the swift code field.

break; // No need to go further if there is a match.

}

}

}

// You can save the above code as a script by right clicking the Variables of the form and Insert Script object

// name the script as bankScript

// -- bankScript end



// In the change event of the dropdown list

bankScript.getBankInfo(xfa.event.newText, txtBankAddressField, txtSwiftCodeField);

//xfa.event.newText Specifies the content of the field after it changes in response to the actions of a user.



Hope It helps

Asiye

Avatar

Former Community Member
Hi Jamie,

Function Code is not displayed good because of comments.

You can use



function getBankInfo(bankName, bankAddField, bankSwiftCodeField)

{

var i;

for (i = 0; i < banks.length; i++)

{

if (banks[i] == bankName)

{

bankAddField.rawValue = bankAdd[i];

bankSwiftCodeField.rawValue = bankSwift[i];

break;

}

}

}

Avatar

Level 1
Hallo Asiye, I was looking for something like you did here, but when I copy/paste and adapt to my environment, I got the error "function 'Array' on line 3, column 42 is unknown"



The reference, I guess, is about:

var banks = new Array(" ","Bank1","Bank2");



what's wrong?



Thank you

Maurizio