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
313 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
  • 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

820 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