I like to use the IIF function, you will find that this will not get screwed up by html editors or page cleanup utils. Sometimes putting a cftag inside an HTML tag can cause problems. I also personally find it more readble.
The IIF function works thus
IIF(condition, true, false)
condition = the condition you want to test
true = what to display/do is condition is true
false = what to display/do if condition is false.
So where you want SELECTED to appear in the tag, you put this.
#IIF(columnNameis 'value', DE('selected'), DE(''))#
Replacing ColumnName with your database column, and value with the value you are checking it is equal to.
E.G.
<input name="locationType" type="radio" value="TypeB" #IIF(LocationType is 'typeA', DE('selected'), DE(''))#>
The DE() function means Delayed evaluation, you can thus use it to display text without trying to ecvaluate a variable. If you do not use DE() then whatever value you have for the true/false coldfusion will try to evaluate.
So where the value of locationType = typeA, the text SELECTED is inserted into the tag, otherwise nothing is inserted.
Regards
Russ Michaels
Main Topics
Browse All Topics





by: reitzenPosted on 2004-08-14 at 00:27:21ID: 11798958
Here's the code you'll need to o show the default value when the page loads:
<input type="radio" name="locationType" value="typeA"<cfif myQuery.locationType EQ "typeA"> selected</cfif>>
<br />
<input type="radio" name="locationType" value="typeB"<cfif myQuery.locationType EQ "typeB"> selected</cfif>>
That's all there is to it.
On a side note, checkboxes work the same way.
HTH
Rob