Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
320 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 2000 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

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

705 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