?
Solved

Dynamically populate check boxes with database information

Posted on 2003-12-02
18
Medium Priority
?
372 Views
Last Modified: 2013-12-24
I have a ColdFusion used to input data into an Oracle database. Most of it is pretty straight forward controls. Now, though, I need to show a series of check boxes. The check boxes need to be dynamically populated with data from the database based on a previous selection. For example, if a user wants to submit a record for the HR department, then a set of checkboxes will display at the bottom based on the HR selection. The user needs to check all that apply, then submit the form. The checkbox data will be stored in one field in the database. I have the form displaying the checkboxes properly, but I do not know how to get it to grab the string values that get checked in order to store them in the table. Any help would be greatly appreciated. Thanks.
0
Comment
Question by:dodgerfan
[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
  • 8
  • 7
  • 2
  • +1
18 Comments
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9862589
are the check boxes the only fields being submitted to this page? do you know the names of the checkboxes or are the completely dynamic?
0
 

Author Comment

by:dodgerfan
ID: 9862803
There are other fields being submitted. The names and values are supposed to be dynamic, based on info from the database table.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9862826
>>The checkbox data will be stored in one field in the database

all the checkboxes are to be stored as cb1,cb2,cb3 in one field?
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:dodgerfan
ID: 9862969
Yes, the checkbox data will be stored in one field in the table, comma delimited. cb1, cb2, cb3 is the right idea. That data (cb1, cb2, cb3) gets pulled from another table and is displayed based on a prior selection. For example, Option one may display cb and cb2. Option two all three, etc.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9863029
i think i'm missing something ....

you are submitting a form with several fields and checkboxes

you want to store the checkbox values as a comma delimited list in a single database field

the names of the field cannot be determined before submitting the form,
can you preface the field names with cb to identify the checkboxes?
0
 
LVL 25

Accepted Solution

by:
James Rodgers earned 2000 total points
ID: 9863065
if yuocan preface the checkbox name with an identifier (eg cb) then this will get the values into a single variable as a comma delimited list

<cfoutput>

<cfif isDefined("form.fieldNames")>
      <cfset listOfCbValues="">
      <cfloop index="fieldName" list="#form.fieldNames#">
              <cfif ucase(left(fieldName,2)) eq "CB">
                  <cfif Len(listOfCbValues)>
                        <cfset listOfCbValues=listOfCbValues & ", ">
                  </cfif>
                  <cfset listOfCbValues=listOfCbValues & #evaluate(fieldName)#>
            </cfif>
      </cfloop>
</cfif>
#listOfCbValues#
</cfoutput>
0
 

Author Comment

by:dodgerfan
ID: 9863149
That looks to me like you have the idea.I apologize if I did not state my question more clearly. I confused myself a little. I'll give this a shot and let you how it works. Thanks.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9863166
>>I apologize if I did not state my question more clearly

no worries, it looks like we're on the right track... thats what matters
0
 
LVL 11

Expert Comment

by:hart
ID: 9864448
ok just a query can't the names of the checkbox be hardcoded to CB..
instead of giving dynamic names.

i am saying this because u already know that these checkboxes are for HR / SOME other stuff.

all u have to do is pass that id or value in an hidden field to the form submission page...

and their store this id / value and then in the next colum just the value of CB in a comma delimited format.
by this u can avoid the loop on the fieldnames....


Regards
Hart
0
 

Expert Comment

by:trr1jdg
ID: 9867532
Try this, I use it to keep track of developers and their application teams.  This piece of code will check a checkbox if the specific users teams are listed in all the teams

I.E.
Team: 1,2,3,4,5,6,7,8,9,10
MyTeam: 2,3,15.5,4

This would display the all 10 checkboxes with 2,3, and 4 checked
Have fun


<cfquery name="listTeam" username="#request.dbuser#" password="#request.dbpass#" datasource="#request.dsn#">
      SELECT * TEAMS
</cfquery>      

<cfquery name="getMyTeam" username="#request.dbuser#" password="#request.dbpass#" datasource="#request.dsn#">
SELECT THE FIELD THAT CONTAINS THE STRING OF TEAMS FOR THE SPECIFIC USER (in my case)
</cfquery>

<cfif parameterexists(getMyTeam) and IsQuery(getMyTeam)>
      <cfloop query="getMyTeam">
            <cfset strMyTeams = ListAppend(strMyTeams,getMyTeam.TEAM)>
      </cfloop>
</cfif>


<table class="borderTop996633" cellpadding="0" cellspacing="0" align='center'>
      <tr valign="top" bgColor="##990000">
            <td class="whiteHeader13px" colspan="2">Add\Remove Application Teams</td>
      </tr>
      
      <cfloop query="listTeam">
      <tr>
            <td colspan="2">
                  <cfif ListContains(strMyTeams, listTeam.TEAM_CD) NEQ 0>
                        <table><tr><td><cfinput class="checkbox" type="checkbox" name="myTeams" value="#listTeam.TEAM_CD#" checked="Yes"/></td><td class="label">#listTeam.TEAM_DISP_NA#</td></tr></table>
                        <!--- <cfinput type="checkbox" value="#listTeam.TEAM_CD#" name="myTeams" > --->
                  <cfelse>
                        <table><tr><td><cfinput class="checkbox" type="checkbox" name="myTeams" value="#listTeam.TEAM_CD#" checked="No"/></td><td class="label">#listTeam.TEAM_DISP_NA#</td></tr></table>
                        <!--- <cfinput type="checkbox" value="#listTeam.TEAM_CD#" name="myTeams"> --->
                  </cfif>
            </td>
            
      </tr>
      </cfloop>                  
</table>
0
 

Author Comment

by:dodgerfan
ID: 9868472
OK, I have not tried the suggestion from trr1jdg yet. I'll take a look. As for Jester_48, I tried the following code:

<CFIF ISDEFINED("FORM.FieldName")>
  <CFSET listofCbValues="">
  <CFLOOP index="fieldName" list="#FORM.FieldName#">
    <CFIF UCASE(LEFT(FieldName, 8)) EQ "CALNAME_">
        <CFIF Len(listofCbValues) GT 0>
            <CFSET listofCbValues=listofCbValues & ", ">
        </CFIF>
        <CFSET listofCbValues=listofCbValues & #evaluate(filedName)#>
    </CFIF>
  </CFLOOP>
</CFIF>
#listofCbValues#

Now, when I submit the data to the database, the the delimited list is submitted as On, On, On, On, instead of actually submitting the values displayed, i.e. HR, Admin etc. Did I miss something? I was wondering if the evaluate part of this is incorrect. Thanks for all of the help.

0
 

Author Comment

by:dodgerfan
ID: 9868525
Sorry, the On, On, On is submitted to the database field correctly, but I want it to submit the values displayed.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9868635
>>On, On, On is submitted to the database field correctly, but I want it to submit the values displayed.

what are the values frio the checkboxes?

set the checkbox value to the group name ie

<input type="checkbox" name="cb_213345" value="hr">

a checkbox will only submit the value if it is checked

if the value is "on" then thre is no way to capture "hr" as all that is submitted from a form is the name value pair of the form elements
textbox=value
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9868653
when you generate the checkbox in the form do it  something like this

<tr><td><input type="checkbox" name="cb_213345" value="#dept#">#dept#</td></tr>
0
 

Author Comment

by:dodgerfan
ID: 9869789
I'll go back and work my way through this with your latest comments. I think we finally reached the root of my original problem. The value of the checkbox is supposed to be dynamically generated from the one of the database tables, then whichever ones are checked should be the delimited string that is inserted into the table that stores the info from the form.
0
 

Expert Comment

by:trr1jdg
ID: 9874316
can you post the SQL statement that pulls the dynamic data to generate the checkboxes?
0
 

Author Comment

by:dodgerfan
ID: 9878154
I got it. Thanks for all of the help. Jester_48, your code helped me gte this straightened out. Thanks for everyone's input.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9878191
np... glad i could help

thanks for the points!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

765 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