8.7. Checks and Selections
A "memory" for drop-down menus, radio buttons and checkboxes can be provided with the [checked] and [selected] tags.
[checked var_name value]
-
named attributes: [checked name="var_name" value="value" cgi=0|1 multiple=0|1 default=0|1 case=0|1]
This will output CHECKED if the variable var_name is equal to value. Set the cgi attribute to use cgi instead of values data. Not case sensitive unless case is set.
If the multiple attribute is defined and set to a non-zero value (1 is implicit) and if the value matches on a word/non-word boundary, it will be CHECKED. If the default attribute is set to a non-zero value, the box will be checked if the variable var_name is empty or zero.
[selected var_name value]
-
named attributes: [selected name="var_name" value="value" cgi=0|1 multiple=0|1 default=0|1 case=0|1]
This will output SELECTED if the variable var_name is equal to value. Set the cgi attribute to use cgi instead of values data. Not case sensitive unless case is set.
If the multiple argument is present, it will look for any of a variety of values. If the default attribute is set, SELECT will be output if the variable is empty or zero. Not case sensitive unless case is set.
Here is a drop-down menu that remembers an item-modifier color selection:
<SELECT NAME="color"> <OPTION [selected name=color value=blue]> Blue <OPTION [selected name=color value=green]> Green <OPTION [selected name=color value=red]> Red </SELECT>
-
For databases or large lists of items, sometimes it is easier to use [loop list="foo bar"] and its option parameter. The above can be achieved with:
<SELECT NAME=color> [loop list="Blue Green Red" option=color] <OPTION> [loop-code] [/loop] </SELECT>
See also the ictags documentation on the [loop] tag.