Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to populate cfselect from array, not from query?

Status
Not open for further replies.

cadoltt

Programmer
Jun 9, 2005
85
CA
Hi Everybody,

Most cases I've found on cfselect explain how to populate it from a query.

Is there a way to do it from an array?

Thanks,

Alex
 
Loop through the elements:
Code:
<cfoutput>
<cfloop index="idx" list="#theArray#" delimiters=",">
<option value=#idx#>#idx#
</cfloop>
</cfoutput>

Regards,
mansii
 
Oops, it's for a list. This is what I did for array:
Code:
<cfset aUBOUND = arrayLen(theArray)>

<cfloop index="i" from="1" to="aUBOUND">
<option value=#theArray(i)#>#theArray(i)#
</cfloop>

Sorry.
 
Hi mansii,

Thank you for this. I see that instead of the CF tag I need the HTML select tag. And the idea is to use CF loop to populate the box.

In fact, I need even a simpler thing than taking values from an array. The box is to be populated with numbers from 1 to 100 (this is a percent box).

So, here is what I did based on your code:

Code:
 <select name="percent" editable="yes">
   <cfloop index="i" from="1" to="100">
     <option value=#i#>#i#</option>
   </cfloop>
 </select>


But instead of numbers the box is getting stuffed with '#i#'. Definitely, I am doing something stupid, but I can't figure out what.


Can you tell me what this is?


Thanks again,

Alex
 
Code:
 <select name="percent" editable="yes">
   <cfloop index="i" from="1" to="100">
     [b]<cfoutput>[/b]<option value=#i#>#i#</option>[b]</cfoutput>[/b]
   </cfloop>
 </select>


Place cfoutput tags around the option generation
 
Safaritek,

It works now - thanks alot!

Alex
 
And, putting the cfoutput outside the cfloop is a performance issue.
Code:
<select name="percent" editable="yes">
[blue]<cfoutput>[/blue]
   <cfloop index="i" from="1" to="100">
     <option value=#i#>#i#</option>
   </cfloop>
[blue]</cfoutput>[/blue]
</select>
 
Thank you for the tip, mansii. I should have noticed the <cfoutput> tag in your first post...

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top