Skip to main content
Inspiring
May 20, 2017
Answered

Javascript: multiple selection list box

  • May 20, 2017
  • 1 reply
  • 2182 views

I want to have a list box with ***multiple selections***... I THEN want another text box to populate based on the selections. I don't want verbatim, I want more than just the selection.

Say "Florida" is selected, I want the field to populate "Florida: Where the beaches are nice"...

Say "Arizona" is selected, I want the field to populate "Arizona: Extremely hot in the summer"... and so on for each selection...

I want to these to accumulate.

This topic has been closed for replies.
Correct answer George_Johnson

The custom calculation script of the text field could be something like:

(function () {

    // Initialize some variables

    var i, aLines = [];

    // Associate states with a description

    var oStates = {

        "Florida" : "where the beaches are nice",

        "Arizona" : "Extremely hot in the summer",

        "Washington" : "the Evergreen State"

   

    }

    // Get the selections from the list box

    var val = getField("List1").value;

    if (typeof val === "object") {

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

            aLines.push(val + ": " + oStates[val]);

        }

    } else {

        aLines.push(val + ": " + oStates[val]);

  }

    // Set this field value

    event.value = aLines.join("\r");

})();

where "List1" is the name of the list box.

1 reply

George_JohnsonCorrect answer
Inspiring
May 21, 2017

The custom calculation script of the text field could be something like:

(function () {

    // Initialize some variables

    var i, aLines = [];

    // Associate states with a description

    var oStates = {

        "Florida" : "where the beaches are nice",

        "Arizona" : "Extremely hot in the summer",

        "Washington" : "the Evergreen State"

   

    }

    // Get the selections from the list box

    var val = getField("List1").value;

    if (typeof val === "object") {

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

            aLines.push(val + ": " + oStates[val]);

        }

    } else {

        aLines.push(val + ": " + oStates[val]);

  }

    // Set this field value

    event.value = aLines.join("\r");

})();

where "List1" is the name of the list box.

Inspiring
May 21, 2017

I tweaked it a little bit (only like \n and \t), but it's working great.