4.66. selected
4.66.1. Summary
Parameters: name value
Positional parameters in same order.
The attribute hash reference is passed to the subroutine after the parameters as the last argument. This may mean that there are parameters not shown here.
Must pass named parameter interpolate=1 to cause interpolation.
Invalidates cache: YES
Called Routine:
ASP-like Perl call:
$Tag->selected( { name => VALUE, value => VALUE, } ) OR $Tag->selected($name, $value, $ATTRHASH); [selected name value other_named_attributes]
Parameters | Description | Default |
case | DEFAULT_VALUE | |
cgi | DEFAULT_VALUE | |
default | DEFAULT_VALUE | |
name | DEFAULT_VALUE | |
multiple | DEFAULT_VALUE | |
value | DEFAULT_VALUE |
Attributes | Default |
interpolate (reparse) | No |
Other_Characteristics | |
Invalidates cache | YES |
Container tag | No |
Has Subtags | No |
Nests | Yes |
Tag expansion example:
[value name=example set=neato] <OPTION[selected example neato]>Neato <OPTION[selected example silly]>Silly --- <OPTION SELECTED>Neato <OPTION>Silly
4.66.2. Description
You can provide a "memory" for drop-down menus, radio buttons, and checkboxes with the [checked] and [selected] tags.
This will output SELECTED if the variable var_name is equal to value. If the optional MULTIPLE argument is present, it will look for any of a variety of values. Not case sensitive unless the optional case=1 parameter is used.
Here is a drop-down menu that remembers an item-modifier color selection:
<SELECT NAME="color"> <OPTION [selected color blue]> Blue <OPTION [selected color green]> Green <OPTION [selected color red]> Red </SELECT>
Here is the same thing, but for a shopping-basket color selection:
<SELECT NAME="[item-modifier-name color]"> <OPTION [selected [item-modifier-name color] blue]> Blue <OPTION [selected [item-modifier-name color] green]> Green <OPTION [selected [item-modifier-name color] red]> Red </SELECT>
By default, the Values space (i.e. [value foo]) is checked -- if you want to use the volatile CGI space (i.e. [cgi foo]) use the parameter cgi=1.
Use the parameter default=1 to specify the option that should be marked SELECTED if the value/CGI variable has never been set.
If the parameter multiple=1 is set, the value parameter can contain multiple (stacked) values that should be selected, separated by ASCII null characters ("\0" in Perl).