options - print options list

SYNOPSIS

<options $values $selected $output
         [$classes [$ids [$titles]]]>


DESCRIPTION
The options function prints an HTML <option> tag for each value in $output. The HTML value attribute is set to the corresponding value of $values. If it matches a value in $selected, then the HTML selected attribute is set. Finally, the value of $output is printed as the user-visible value of the tag.

If there are fewer values of $values than $output, the remaining options do not have value attributes set (and the $output value is checked instead for the selected attribute). Thus, a no-values $values argument would cause no value attributes at all to be set. This can be used to minimize the amount of HTML text sent for a large list of small values. Note that if $values is a single empty-string value, it is also treated as an empty list (no values); this allows a literal empty string to be passed to indicate "no value attributes". (To ensure value attributes are always set, make sure $values has at least two values, even if empty.)

In version 5.01.1219783000 20080826 and later, the output is XHTML 1.0 Strict compliant, and the optional $classes and $ids arguments may be given. The $classes argument is a parallel list of class attribute values to set; if the list is short, the last value is re-used. If no values (or a single empty value) is given, no class attributes are set.

The $ids argument is a parallel list of HTML id attribute values to set; if the list is short, the last value is re-used, but with its last numeric section incremented each time (to make it unique). This allows control of the starting id value, with the convenience of the function making the rest of the sequence unique. If no values (or a single empty value) is given, no ids are printed. Empty $ids values in the middle of the list will be printed as "option" with an incrementing number.

In version 5.01.1225758000 20081103 and later, an optional $titles argument may be given. If non-empty, each value specifies the title attribute to set for the corresponding item.


DIAGNOSTICS
options returns nothing.


EXAMPLE

<$values = red green yellow blue>
<$selected = green>
<select name="color">
<options $values $selected $values>
</select>


CAVEATS
The options function was added Sep. 20 1996. The $classes and $ids arguments were added in version 5.01.1219783000 20080826.

All values are HTML-escaped when printed.


SEE ALSO
radiobutton, checkbox


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.