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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkboxes &lists

Status
Not open for further replies.

Jawa

Programmer
Feb 21, 2002
74
US
Hope someone can help.

I am dynamically creating checkboxes from a comma seperated list (i.e., sam, mary, howard, pam). I am saving the data I check off to the database as a comma seperated list (i.e., mary, pam). When I pull up the record to edit it, how do I code it to mark the checkboxes as checked for the values that were selected already?

Thank you for any help.
 
Hi mate,

Only been using CF for a few weeks so there may be a better solution to this.

<INPUT TYPE=&quot;CHECKBOX&quot; NAME=&quot;whatever&quot; VALUE=&quot;mary&quot; <cfif your.query contains &quot;mary&quot;> checked</cfif>>

Hope this helps Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
Thank you. I had tried this approach. My issue is that I have to go after a list and loop around it to compare to another list.

For Example:

The values in my data fields are mary,pam and the values I need to compare them to are mary,pam,joe,paul,making sure I only have mary and pam as checked.

 
the list of values that you loop over to create the checkboxes is &quot;the list of all available values&quot; and now you want to see which of these were previously selected, which is a list retrieved from the database

what you have to do is loop over all the available options, and check each one to see if it's in the selected list

this can be done with

ListFind(selectedlist,ListGetAt(availablelist,x))

x is the loop index, looping over all available values


rudy
 
SUPER. That appears to be what I need to do. If I could ask one more thing? My list has months in this case and I am getting the following error:


The value &quot;january&quot; cannot be converted to a number

Here is my code:

<cfset shmoo = &quot;#thisVar.XmlAttributes['values']#&quot;>
<cfloop index=&quot;i&quot; list=&quot;#shmoo#&quot; delimiters=&quot;,&quot;>
<input type=&quot;checkbox&quot; name=&quot;XML_#thisVar.XmlName#&quot; id=&quot;XML_#thisVar.XmlName#&quot; value=&quot;#i#&quot; <cfif ListFind(thisVar.XmlText,ListGetAt(shmoo,i))>checked</cfif>>#i#<br>
</cfloop>

Thank you for your direction!
 
you're getting that error because the second parameter of ListGetAt is supposed to be a number

i'm not 100% sure without testing your code (which i may not get around to, this being the most hallowed sunday of the year), but your loop index takes the values of the list items, so you want ListFind(thisVar.XmlText,i), whereas my example assumed an index taking values from 1 to ListLen(shmoo) and hence requiring ListGetAt()

pick one or the other, they seem equivalent (unless someone steps in to say which way is faster, similar to the way Compare() is supposedly faster than EQ)


rudy
 
THANK YOU!! GOT IT!!

ENJOY YOUR SUNDAY!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top