Solved

Concatenate Check Box Values

Posted on 2001-07-16
7
189 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 250 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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