I have been using ColdFusion 8 / 9 / 10 regularly. The code below works just great in CF9 and CF10. (I developed it in 9). It does NOT work in CF8 though.
If you run the code below (at the bottom) in CF9 and CF10, you should get the HTML results immediately below:
<select>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option selected="" value="3">Option 3</option>
</select>
If you run the code below in CF8, you'll get this error:
The SELECTED parameter to the WrapOption function is required but was not passed in.
In CF8, how would I modify this code to make the "selected" parameter (or any other parameter) optional in CF8?
<cfscript>
Options = WrapOption("Option 1", 1);
Options = Options & WrapOption("Option 2", 2);
Options = Options & WrapOption("Option 3", 3, "Selected");
SelectBox = WrapSelect(Options);
writeOutput(SelectBox);
// WRAP OPTION
function WrapOption(Content, Value, Selected) {
LOCAL.Content = ARGUMENTS.Content;
LOCAL.Properties = " value='#ARGUMENTS.Value#'";
// SELECTED
if (structKeyExists(ARGUMENTS, "Selected")) {
LOCAL.Properties = LOCAL.Properties & " selected";
}
LOCAL.Item = "<option #LOCAL.Properties#>#LOCAL.Content#</option>";
return LOCAL.Item;
}
// WRAP SELECT
function WrapSelect(Options, Class, ID) {
LOCAL.Options = ARGUMENTS.Options;
LOCAL.Properties = "";
// CLASS
if (structKeyExists(ARGUMENTS, "Class")) {
LOCAL.Properties = LOCAL.Properties & " class='#ARGUMENTS.Class#'";
}
// ID
if (structKeyExists(ARGUMENTS, "ID")) {
LOCAL.Properties = LOCAL.Properties & " id='#ARGUMENTS.ID#'";
}
LOCAL.Item = "<select #LOCAL.Properties#>#LOCAL.Options#</select>";
return LOCAL.Item;
}
</cfscript>