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

check box values, take two 1

Status
Not open for further replies.

simmerdown

Programmer
Jun 6, 2000
100
US
I first generate a list of checkboxed items based on a query

<cfoutput query=&quot;equiplist&quot;>
<tr>
<td><input type=&quot;checkbox&quot; name=&quot;equip_item&quot; value=&quot;#Item#&quot;></td>
<td class=&quot;eq1&quot;>#Item#</td>
</tr>
</cfoutput>

like so. The name (&quot;equip_item&quot;) is of course applied to every checkbox in the list.

This is submitted to a page which inserts the items and a userID into my results table ... and we come to my dificulty. The values from the checkboxes are all combined into one value, since all my checkboxes have the same name. Thus I end up with a string such as &quot;Audio CD Player,DVD Player,Slide Projector&quot; as my (single) value.

Is it within the realm of possibility to
a) give each checkbox a unique name on the fly, or
b) split the values up again so that each one can be inserted into the db as a distinct value? I'm even thinking that some sort of looping insert, placing the userID and a single item value on each row, might be a good way to go ... if you could be kind enough to give me a start.

Thanks in advance. I've looked around, but haven't seen this problem addressed specifically.
 
a) a_cf_string=&quot;equip_item&quot;&&quot;#a_counter#&quot; (&quot;a_counter&quot; can be &quot;currentrow&quot;) - then you'll get equip_item1, equip_item2, ... becareful when it comes to read their value, as you'll have first to build a_cf_string as above, and then, EVAL it to get its value, or else, it won't work
b) i know there is a cf function that splits string as you want to, you just give to the function : the string and the token/the separator (&quot;,&quot; for you), and the function returns a list (or an array?) of strings - unfortunatly i can't remember the name of this function and i don't have the doc - if you have the doc or can access it, it's right there !!!!
 
a)You rule, Iza ...
[COLOR=006633]<cfoutput query=&quot;equiplist&quot;>
<cfset name_string = &quot;equip_item&quot;&&quot;#equiplist.CurrentRow#&quot;>name=&quot;#name_string#&quot;>
<input type=&quot;checkbox&quot; name=&quot;#name_string#&quot; value=&quot;#Item#&quot;>
</cfoutput>[/color]
did the trick.

b) I've got the docs right here ... any of these tempting-looking functions ring a bell?[ul]
[li]RemoveChars(string, start, count)
[li]Replace(string, substring1, substring2 [, scope ])
[li]ReplaceList(string, list1, list2)
[li]RTrim(string)
[li]Trim(string)
[li]UCase(string)
[li]Val(string)
[li]ArrayToList(array [, delimiter ])
[li]ListAppend(list, value [, delimiters ])
[li]ListChangeDelims(list, new_delimiter [, delimiters ])
[li]ListQualify(list, qualifier [, delimiters ]
[, elements ])
[li]ListRest(list [, delimiters ])
[li]ListToArray(list [, delimiter ])
[li]ListValueCount(list, value [, delimiters ])
[/ul]
I'm going to start trying them out, but if you recognize the one you mentioned previously, toss me a heads-up.
Many thanks
 
My cf_unfamiliarity is showing.

I ended up going with approach (b), which needed only a simple cfloop:
[COLOR=006633]
<cfloop index=&quot;Item&quot;
list=&quot;#Form.equip_item#&quot;>[/color][COLOR=003366]
<cfquery name=&quot;insertinfo&quot; DataSource=&quot;#DataSource#&quot;>
INSERT INTO ItemUse (UserID, Item)
VALUES (#User.UserID#, '#Item#')
</cfquery>[/color][COLOR=006633]
</cfloop>
[/color]
to do the job perfectly.

 
fine ! i'm happy it finally works for you :)))
and yes, you got the easiest way to do it !!! nice :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top