Page 1 of 1

Multiple Selection Text Box

Posted: Wed Mar 01, 2017 4:49 pm
by rrogulski
We are working with a multiple selection text box using javascript. Is there a way to retrieve all of the selected items? We have tried several of the value retrieval functions but they all return only the first selected value.

Re: Multiple Selection Text Box

Posted: Wed Mar 01, 2017 5:36 pm
by Glenn
Rob,

Can I assume you are talking about a dropdown (officially known as a 'select box') widget?

If so, you could use some code like what's below to find out which items are selected. Note that the getObj() api shown requires the ID of the element you are working with.

Code: Select all

var i;
// For readablity
var mySelect = getObj("Dropdown1");

// Loop through the 'option' properties of the select box object and look
//  for those where the 'selected' property is true.
for (i=0 ; i < mySelect.options.length ; i++) {
  if (mySelect.options[i].selected) {
    // The 'value' property contains the entries from the 'choice values' property of the select box  
    // The 'innerHTML' property contains the entries from the 'choices' property of the select box 
    alert(mySelect.options[i].value + ' - ' + mySelect.options[i].innerHTML);
  }
}
Glenn