BuildOptionList()

Creates a set of <option> tags that you can integrate into an HTML form on webpage.

Availability

<table> <tr> <td>Marketing Cloud Engagement</td> <td>✅ Yes</td> </tr> <tr> <td>Marketing Cloud Next</td> <td>❌ No</td> </tr> </table>

Syntax

BuildOptionList(defaultSelection,
                option1Value, option1Text,
                [option2Value, option2Text] ... )

The BuildOptionList() function has three parameters:

  • defaultSelection (string or number): Required. The option that is selected by default.
  • option1Value (string): Required. An identifier for the first option. The function sets the value parameter in the <option> tag to this value.
  • option1Text (string): Required. The display text for the option tag.

Each option in the list requires a value and a display text. You can create as many options as you need by appending them to the end of the function (option2Value, option2Text...).

Usage

To use this function, specify a default selection, and a value and display name for each option that you want to generate.

This example creates a short list of options, and embeds it in an HTML form that asks the user to choose one:

%%[
set @DefaultOption = 2
set @OptionList = BuildOptionList(@DefaultOption,
                                  "1", "Option A",
                                  "2", "Option B",
                                  "3", "Option C")
]%%
<p>Choose an option:</p>
<select name="choice">
%%=v(@OptionList)=%%
</select>

The example outputs this HTML code.

<p>Choose an option:</p>
<select name="choice">
  <option value="1">Option A</option>
  <option value="2" selected="selected">Option B</option>
  <option value="3">Option C</option>
</select>

In a web browser, the generated code resembles this example.

A simple HTML form that contains a dropdown list. The text "Choose an option" is shown above the list. In the list itself, Option B is chosen by default.