Form Select List Custom Tag

Download FormSelect.zip (3K)

Description

Requires ColdFusion 5 or greater.

FormSelect.cfm is a ColdFusion custom tag that creates a standard HTML form select list from a field name and a list of values.

Syntax

<CF_FormSelect
	FIELD="form field name"
	VALUES="list of values"
	[LABELS="list of labels"]
	[SELECTED="selected value"]
	[DELIM="list delimiter"]
	[ONCHANGE="JavaScript"]
	[MULTI="boolean"]
	[SIZE="number"]
	[TABINDEX="number]"]
	[STYLE="CSS string"]
	[CLASS="string"]
	[ID="string"]
	[NULLOPTION="string"]
	[COMPRESS="boolean"]
>

Attributes

CLASS     (optional, string)     Text to place in the select tag's CLASS parameter. If empty, parameter is not used.
COMPRESS     (optional, booelan)     Remove all multiple whitespaces (tab, space, CR) but leave single occurences. Default is "YES".
DELIM     (optional, string)     Delimiter used by all list values. Default is a comma (",").
FIELD     (REQUIRED, string)     A valid HTML form field name for the select list.
ID     (optional, string)     Text to place in the select tag's ID parameter. If empty, parameter is not used.
LABELS     (optional, string list)     A delimited list of labels for the select list. If provided, number of labels must equal number of values. If omitted, values are used as labels.
MULTI     (optional, boolean)     Does select list accept multiple selections? Forced to "YES" if SELECTED parameter contains multiple values. Default is "NO".
NULLOPTION     (optional, string)     Label for initial option with a null/empty string value (used for instructions or other initial null value needs.)
ONCHANGE     (optional, string)     JavaScript to execute when new item is selected.
SELECTED     (optional, string|string list)     Value of the list options to mark as selected. If omitted or not present in list of values, first value is used. If multiple values are entered, select list is set to MULTIPLE to allow multiple selections.
SIZE     (optional, number)     Size of select list. 0 = pull-down (or browser-dependent autosize for multiple), 1 or greater forces display size. Default is "0".
STYLE     (optional, string)     CSS text to place in the select tag's STYLE parameter. If empty, parameter is not used.
TABINDEX     (optional, number)     Number to place in the select tag's TABINDEX parameter. If empty, parameter is not used.
VALUES     (REQUIRED, string list)     A delimited list of values for the select list. If no labels are provided, these will also be used as labels. If a value is set to "[NULL]" (without the quotes), an empty string is used.

Examples

Please select an item:

<B>Please select an item:</B>
<CF_FormSelect 
	FIELD="Items" 
	VALUES="#ValueList(MyQuery.Column1,Chr(7))#" 
	LABELS="#ValueList(MyQuery.Column2,Chr(7))#"
	DELIM="#Chr(7)#">

Please rate our product:

<P><B>Please rate our product:</B>
<CF_FormSelect 
	FIELD="RatingScale" 
	VALUES="Poor,Good,Excellent" 
	SELECTED="Good">

Shipping method:

<P><B>Shipping method:</B>
<CF_FormSelect 
	FIELD="Shipping" 
	VALUES="1:2:3" 
	LABELS="FedEx, Ground:UPS, Overnight:UPS, 2nd Day" 
	DELIM=":" 
	ONCHANGE="alert('Good choice!');">

Areas of interest:

<P><B>Areas of interest:</B>
<BR><CF_FormSelect 
	FIELD="Interest" 
	VALUES="cf,css,html,js,xml" 
	LABELS="ColdFusion,CSS,HTML,JavaScript,XML" 
	SELECTED="cf,html" 
	SIZE="10" 
	MULTI="yes">

Site last updated: 11 March 2012