Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Concatenate Check Box Values

Posted on 2001-07-16
7
Medium Priority
?
197 Views
Last Modified: 2013-12-24
On my form I have 30 checkboxes with different values and names. I would like to concatenate the values of all the check boxes to one long text string to be inserted in to a SQL Server database using POST method to insert.cfm. I use CFINSERT in the insert.cfm with fromfields. The datbase field is "Councils".

This is an example of the code used on the form for the check boxes:

<tr>
     <td><input type="checkbox" name="cc1" value="All">All Community Councils</td>
     <td><input type="checkbox" name="cc2" value="Abbott Loop">Abbott Loop</td>
     <td><input type="checkbox" name="cc3" value="Airport Heights">Airport Heights</td>
</tr>
<tr>
     <td><input type="checkbox" name="cc4" value="Basher">Basher</td>
     <td><input type="checkbox" name="cc5" value="Bayshore">Bayshore</td>
     <td><input type="checkbox" name="cc6" value="Bear Valley">Bear Valley</td>
</tr>

Any code on how to do this?

0
Comment
Question by:apwbe
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:mor4eus
ID: 6288200
There is probably a better way to do this but this is how I would do this.
The problem is, with checkboxes, when you pass them to the next page, if they are unchecked the variable isn't passed, you may want this, but if not you will need lots of IsDefined. Also it is best not to use cfinsert but write a query.

So...
This is your insert.cfm

<cfset IsDefined("cc1")><cfelse><cfset cc1=0></cfif>
<cfset IsDefined("cc2")><cfelse><cfset cc2=0></cfif>

<cfquery name="insert" dataousrce="yourdatasource">
INSERT
    tablename (CC1, CC2, CC3, CC4........)
VALUES
    ('#CC1#', '#CC2#', .......)
</cfquery>
   

Hope this helps.  I am sure there could be a better way though.  But this works.
0
 
LVL 37

Expert Comment

by:meverest
ID: 6288306
hi,

you know that if you set all the checkbox names to the same value that the form output will be a comma delimited concatenation?

eg:

<tr>
    <td><input type="checkbox" name="cc" value="All">All Community Councils</td>
    <td><input type="checkbox" name="cc" value="Abbott Loop">Abbott Loop</td>
    <td><input type="checkbox" name="cc" value="Airport Heights">Airport Heights</td>
</tr>
<tr>
    <td><input type="checkbox" name="cc" value="Basher">Basher</td>
    <td><input type="checkbox" name="cc" value="Bayshore">Bayshore</td>
    <td><input type="checkbox" name="cc" value="Bear Valley">Bear Valley</td>
</tr>

then access ALL the checked items as #form.cc1#

assuming that your cc2, cc4 and cc6 are checked, then #form.cc# will come out like:  "Abbott Loop, Basher, Bear Valley"

cheers.


0
 
LVL 37

Accepted Solution

by:
meverest earned 1000 total points
ID: 6288308
hi,

you know that if you set all the checkbox names to the same value that the form output will be a comma delimited concatenation?

eg:

<tr>
    <td><input type="checkbox" name="cc" value="All">All Community Councils</td>
    <td><input type="checkbox" name="cc" value="Abbott Loop">Abbott Loop</td>
    <td><input type="checkbox" name="cc" value="Airport Heights">Airport Heights</td>
</tr>
<tr>
    <td><input type="checkbox" name="cc" value="Basher">Basher</td>
    <td><input type="checkbox" name="cc" value="Bayshore">Bayshore</td>
    <td><input type="checkbox" name="cc" value="Bear Valley">Bear Valley</td>
</tr>

then access ALL the checked items as #form.cc1#

assuming that your cc2, cc4 and cc6 are checked, then #form.cc# will come out like:  "Abbott Loop, Basher, Bear Valley"

cheers.


0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 1

Expert Comment

by:mor4eus
ID: 6288371
I didn't know that. That's great. Really.
How's the weather in melbounre today?
0
 
LVL 37

Expert Comment

by:meverest
ID: 6288421
raining - of course! ;-)
0
 
LVL 1

Expert Comment

by:mor4eus
ID: 6288429
Meverest, have you got an email I can catch you on?
0
 

Author Comment

by:apwbe
ID: 6290510
Thanks,

Saved me a bunch. Raining here in Alaska also, actually been raining for 3 weeks.

Warren
0

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question