Solved

is there a way i can show in my form that a checkbox is checked according to the entry in my sql table field.

Posted on 2012-03-28
5
314 Views
Last Modified: 2012-04-02
Please see attached image before you read my question.

There is a SQL Database has this type of field.
Column Name: CMTEE_PREF and the Data Type varchar 25

I did a Coldfusion query and i'm able to retreive data in that data field. Data was
POL,SOP,EE,TF

Now I have a form with 4 checkbox, one for POL, SOP, EE, and TF.

Is there a way, that a checkbox can be clicked if the pol, sop, ee or TF was entered in the table. I would like to show that the checkbox is clicked if POL, SOP, or EE, or TF was in my CMTEE_PREF field ? Any way i can do that ?

This is my form code:

.......
This is your database results: <cfoutput><input type="text" name="CMTEE_PREF" value="#DisplayCVITool.CMTEE_PREF#" style="width: 200px;background:red;"></cfoutput><br>
             
<input type="checkbox" name="CMTEE_PREF" id="CMTEE_PREF1" value="POL">&nbsp;<label>Policy setting committees (POL)</label><br>

<input type="checkbox" name="CMTEE_PREF" id="CMTEE_PREF2" value="SOP">&nbsp;<label>Standard of practice setting committees (SOP)</label><br>

<input type="checkbox" name="CMTEE_PREF" id="CMTEE_PREF3" value="EEP">&nbsp;<label>Committees related to education and eligibility issues <em>(EE)</em></label><br>

<input type="checkbox" name="CMTEE_PREF" id="CMTEE_PREF4" value="ADMIN">&nbsp;<label>Administrative committees such as Finance or Elections <em>(ADMIN)</em></label><br>

<input type="checkbox" name="CMTEE_PREF" id="CMTEE_PREF5" value="TF">&nbsp;<label>Task Forces (typically short term commitment) <em>(TF)</em></label><br>

<input type="checkbox" name="CMTEE_PREF" id="CMTEE_PREF6" value="ANY">&nbsp;<label>Doesn’t matter, I just want to volunteer. <em>(ANY)</em></label>
SQL-Table.jpg
CMTEE-PREF.jpg
0
Comment
Question by:LelloLello
[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
5 Comments
 
LVL 9

Expert Comment

by:rajeevnandanmishra
ID: 37777298
Hi,
I am not sure about JAVA, but in most of the languages, you can "split" the string in an array with a delimeter and then run the LOOP to check what all you need to mark "Checked".

If you want that your SQL Data should come in any different format (which helps you to mark check) then let us know the format.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 37777337
For each checkbox, use list functions to determine if the current box's value is contained in the list. For example using "POL"

<input type="checkbox" name="CMTEE_PREF" id="CMTEE_PREF1"
      value="POL"
     <cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "POL")>checked</cfif>
>&nbsp;<label>Policy setting committees (POL)</label><br>

Repeat that code with the other checkboxes, using each box's value ie "SOP", "EE" and "TF".

But as an aside, you normally want to avoid storing lists. It's error prone and requires unnecessarily complex queries to answer questions like "how many people selected "EE". Such queries are almost always slower than the alternatives.  A better structure is to use 3 tables, with each combination UniqueID + Preference ie "EE" stored in a separate record.
0
 

Author Comment

by:LelloLello
ID: 37777511
Excellent... Do you know i've still have a problem with a question it's a radio button... if i don't select yes or no i'm getting an error i wil post this new question please advice.
0
 

Author Closing Comment

by:LelloLello
ID: 37777513
Super!
0
 

Author Comment

by:LelloLello
ID: 37798516
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

752 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