webMathematica`

HTMLSelect

HTMLSelect[options, name]

returns an HTML select tag with the given set of options

HTMLSelect[options, values, name]

returns an HTML select tag with the given set of options, mapping to the corresponding values

HTMLSelect[options, name, default]

sets the default

Details

  • The HTML functions are contained in a package, MSP`HTML`, which is loaded as part of the webMathematica layout.
  • The function HTMLSelect provides a useful way to generate select tags which browsers typically render as a drop-down menu, corresponding to Mathematica's PopupMenu.
  • It is also possible to set selections by using the option SelectedOptions.
  • HTMLSelect takes the following options.
  • SelectedValuesinitial selection based on values
    SelectedOptionsinitial selection based on options
    OptionAttributesattributes to apply to the HTML select tag

Examples

open allclose all

Basic Examples  (1)

You can demonstrate how the function works by installing and loading the package:

The function HTMLSelect provides a useful way to generate select tags with webMathematica. It takes a list of the different options and the name to be used when the selection is submitted. Its operation is shown below.

A typical browser will show this as a dropdown menu:

When an HTML form is submitted using this select, the variable $$arg1 will be set to the value of the selected option. In this example $arg1 will be set to 1 if "voltage" is selected, 2 if "current" is selected, and 3 if "resistance" is selected, according to the value assignments.

By default, the values for the option tags are chosen automatically as numbers from 1 to the number of options. It is also possible to set these with an argument.

It is also possible to set the initial selection by using the option SelectedOptions. Typically only one option is selected. In this example, the option labeled "b" will be selected.

The browser will show "b" initially selected:

Selecting the initial option by its value instead of its label can be done with the option SelectedValues.

If no values are given, the SelectedValues option can use the numerical values.

Scope  (1)

You can insert additional HTML attributes into the select tag by passing them as options. This uses the size attribute to produce a list box rather than a drop-down menu.

The browser shows a list box with 4 rows visible and a scrollbar to access other choices:

The selection options can take a list of values to set a multiple selection. You will also want to set the size and multiple attributes so the browser displays the selection as a list box that allows control-click to select multiple items.

The browser shows a list box with multiple items selected: