HTMLSelect


returns an HTML select tag with the given set of options


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


sets the default

DetailsDetails

  • 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

ExamplesExamplesopen allclose all

Basic Examples (1)Basic Examples (1)

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

In[1]:=
Click for copyable input

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.

In[2]:=
Click for copyable input
Out[2]=

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.

In[3]:=
Click for copyable input
Out[3]=

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.

In[4]:=
Click for copyable input
Out[4]=

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.

In[5]:=
Click for copyable input
Out[5]=

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

In[6]:=
Click for copyable input
Out[6]=
New to Mathematica? Find your learning path »
Have a question? Ask support »