Solved

Concatenate Check Box Values

Posted on 2001-07-16
7
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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