Multiple-choice Select tags are functionally directly equivalent to a group of checkboxes. There's one difference: a Select tag has its options defined as a set of option tags. In EWD, you should define those option tags within the page's pre-page script. Let's imagine we want an HTML form in our EWD page that contains a Select tag that displays a set of cities. In your EWD page you would simply have the following:

   City: <select name="city" multiple="multiple"></select>

Note that you don't define any option tags and no logic is included in the EWD page to define how an option is pre-highlighted when the page loads. All this logic is placed in the page's pre-page script.

To define the option tags, you use the appendToList API method, for example:

  d clearList^%zewdAPI("city",sessid)
  d appendToList^%zewdAPI("city","London","lon",sessid)
  d appendToList^%zewdAPI("city","New York","nyc",sessid)
  d appendToList^%zewdAPI("city","Sydney","syd",sessid)
  d appendToList^%zewdAPI("city","Paris","par",sessid)

Note the clearList call which clears out any existing options for the city drop-down. Also note that the order in which you call the appendToList method determines the order in which the options are displayed in the drop-down list.

To pre-highlight one or more options when the page is displayed, in the page's pre-page script, set the corresponding EWD Selected Array values, mapping via the field's name, eg

  d addToSelected^%zewdAPI("city","lon",sessid)
  d addToSelected^%zewdAPI("city","syd",sessid)

In this case the options London and Sydney will be highlighted when the page is displayed. Of course, typically you'll determine the value to highlight based on information retrieved from the database.

When the form is submitted, the value(s) highlighted by the user are copied automatically into the EWD Selected Array. The form's Action Script processes the Selected Array in the same way as for a group of checkboxes. When the form is submitted, the associated Action Script can simply check whether or not a value is in the matching Selected array, eg:

  i $$isSelected^%zewdAPI("city","lon" sessid) d ##class(ewd.examples).doIt("london")

Alternatively you can merge the Selected array to a local array and process the value(s) appropriately, eg:

  d getMultipleSelectValues^%zewdAPI("city",.cities,sessid)

In this example, if the form had been submitted with New York and Paris checked, the cities array would contain:

  cities("nyc")="nyc"
  cities("par")="par"

Click the Enterprise Web Developer/Examples tab for worked examples.