Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Javascript to clear a populated field

Jodi1725
Level 4
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
Jono_Moore
Correct answer by
Level 10
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
Jono_Moore
Correct answer by
Level 10
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

radzmar
Level 10
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;

}

Jodi1725
Level 4
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

Jodi1725
Level 4
Level 4

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

Thank you so much!

Have a fantastic day!

Jodi

Jodi1725
Level 4
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