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.
SOLVED

Javascript to clear a populated field

Avatar

Level 4

Hello all!

I am looking for help   I have a form where I have two dropdowns.  When you choose an item from the first drop down it populates the list for the 2nd dropdown.  Problem is when the user decides to change their mind on the first dropdown and the 2nd drop down is already populated the new list appears but the field within the dropdown doesn't clear for the user to make a new choice.  How can I get the field to clear?

Here is the script I am using

Java.PNG

Thanks!!!

Jodi

1 Accepted Solution

Avatar

Correct answer by
Level 10

Set the rawValue to "". So: CST.rawValue = "";

You can put that (and the clearItems() line) above the if statement - it has to happen every time so no need to repeat it in each if statement.

View solution in original post

5 Replies

Avatar

Correct answer by
Level 10

Set the rawValue to "". So: CST.rawValue = "";

You can put that (and the clearItems() line) above the if statement - it has to happen every time so no need to repeat it in each if statement.

Avatar

Level 10

Hi,

I would solve this the following script in the change event of CT dropdown box.

// Arrays with values for CTS dropdown box

var arrayA = ["Student Placement Clinical", "Student Placement Non-Clinical", "Government-Fundend"];

var arrayB = ["Games", "Premium Seating License", "Consession Stands"];

// Function to populate CTS

function populate(arrayName) {

          CTS.clearItems();

          for (var i = 0; i < arrayName.length; i += 1) {

                    CTS.addItem(arrayName[i], (i + 1).toString());

          }

          xfa.host.openList(CTS.somExpression);

}

// Switch function to determine which array to populate in CTS

switch (xfa.event.change) {

case "Affilitation Agreements" : populate(eval(arrayA)); break;

case "Athletic Event Agreements" : populate(eval(arrayB)); break;

}

Avatar

Level 4

Thanks!!! I am going to go with Jono's first to see if it works.  Radzmar's is a little more advanced than I have done   If I can't get Jono's to work I might be back!

Thanks!!

Jodi

Avatar

Level 4

Jono you are a life saver!!! that worked!!

Thank you so much!

Have a fantastic day!

Jodi

Avatar

Level 4

Hey Radzmar,

Jono's worked!  Thanks for taking the time to reply!  When i get better at Javascript i might try yours
Thanks!
Jodi