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
308 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sql query 7 35
Angular - (very close) following an example 20 34
Re-position the objects 7 51
SQL Split character from numbers 3 16
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
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…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now