[thelist] CF Radio Buttons Tip

matthew garrett matthew.garrett at snet.net
Thu Mar 22 12:14:28 CST 2001


Thank you Joshua.
That looks more proper/efficient. Another tool in the belt...

Before I post this as a tip, how would you improve it?

<cfset answers = '#one#, #two#, #three#, #four#, #five#, #six#, #seven#,
#eight#, #nine#, #ten#'>
<cfset key = 'a,b,c,d,e,a,b,c,d,e'>
<cfset correct="0">
<cfset loopcount="1">
<cfloop index="current" list="#answers#">
  <cfoutput>
    <cfif trim(current) IS '#trim(listGetAt(key, loopcount))#'>
        <p>Right you are! Question #loopcount# is #listGetAt(key,
loopcount)#.</p>
        <cfset correct = '#incrementValue(correct)#'>
    <cfelse>
        <p>Hey, you got this one wrong. Question #loopcount# is actually
#listGetAt(key, loopcount)#, not #current#.</p>
    </cfif>
    <cfset loopcount = '#incrementValue(loopcount)#'>
  </cfoutput>
</cfloop>

<cfoutput>
    <p>You got this many right: #correct#</p>
</cfoutput>

Matt

> From: "Joshua OIson" <joshua at alphashop.net>
> It's always nice to get tips for automating tedious tasks.  Some of the
> newer versions of ColdFusion introduced functions and tags that may even
> make the tasks easier.  The code you gave could be replaced with the
> following:
> 
> <!--- list radio button names in a variable --->
> <cfset checker = 'one,two,three,four,five,six,seven,eight,nine,ten'>
> <!--- loop through them --->
> <cfloop index="next" list="#checker#">
> <cfparam name="form.#next#" default="">
> </cfloop>





More information about the thelist mailing list