How do you display a Checked button.

Posted on 2013-06-13
Medium Priority
Last Modified: 2013-07-03
I have the field CMTEE_PREF_NEW

it has this information (POL,SOP,EE,ADMIN,TF,ANY)

My question has 6 checkbox. How I can make the checkbox checked when the user load that forms to update his profile...

This is my coldfusion cfouput


I will get this information: POL,SOP,EE,ADMIN,TF,ANY

How I can checked into the forms? when the user load the forms...

[x] Policy setting committees (POL)
[x] Standard of practice setting committees (SOP)
[x] Committees related to education and eligibility issues (EE)

this is my code.

            <label for="strEmail"><strong><strong>2.</strong> We have categorized the various committees.  Which of the following types of committee would you prefer to serve on?</label>
          <table border="0" cellspacing="0" cellpadding="0" width="100%" class="qtable">
              <td colspan="2" height="5" width="100%"><!---  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>--->
                <input type="checkbox" name="CMTEE_PREF_NEW" id="CMTEE_PREF1" 
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "POL")>checked</cfif>>
                <label>Policy setting committees (POL)</label>
                <input type="checkbox" name="CMTEE_PREF_NEW" id="CMTEE_PREF2" 
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "SOP")>checked</cfif>>
                <label>Standard of practice setting committees (SOP)</label>
                <input type="checkbox" name="CMTEE_PREF_NEW" id="CMTEE_PREF3" 
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "EE")>checked</cfif>>
                Committees related to education and eligibility issues <em>(EE)</em></
                <input type="checkbox" name="CMTEE_PREF_NEW" id="CMTEE_PREF4" 
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "ADMIN")>checked</cfif>>
                <label>Administrative committees such as Finance or Elections <em>(ADMIN)</em></label>
                <input type="checkbox" name="CMTEE_PREF_NEW" id="CMTEE_PREF5" 
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "TF")>checked</cfif>>
                <label>Task Forces (typically short term commitment) <em>(TF)</em></label>
                <input type="checkbox" name="CMTEE_PREF_NEW" id="CMTEE_PREF6" 
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "ANY")>checked</cfif>>
                <label>Doesn’t matter, I just want to volunteer. <em>(ANY)</em></label></td>

Open in new window

Question by:koila
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
  • 2
LVL 52

Expert Comment

ID: 39245957
I'd recommend NOT storing lists in a db table, because it's error prone, not to mention extremely hard to query. For example,  how would you find all records with both 'TF' and 'EE'?

That said, while I can't test it now - your code should work.  Unless maybe your list contains different values or extra spaces? Lists are extremely sensitive to *any* differences, including spaces, which is one of the reasons to avoid them ...

Test case:

<cfset DisplayCVITool.CMTEE_PREF = "POL,SOP,EE">
POL <input type="checkbox" name="CMTEE_PREF_NEW" value="POL"
        <cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "POL")>checked</cfif>>
SOP <input type="checkbox" name="CMTEE_PREF_NEW" value="SOP"
        <cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "SOP")>checked</cfif>>
EE  <input type="checkbox" name="CMTEE_PREF_NEW" value="EE"
        <cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "EE")>checked</cfif>>

Author Comment

ID: 39248071
Hello Agx,

So your recomandation is to have a field YES NO for POL
and YES No for SOP ?

thank you,
LVL 52

Expert Comment

ID: 39248955
(Edit) No, I usually create a separate table for storing many-to-many relationships. Have a separate table for distinct volunteers and categories. Then store each volunteer + category in a 3rd table, as a separate record.  

Volunteer      Unique volunteer records ..
Columns: VolunteerID (PK), FirstName, LastName, .....

Category:   Distinct categories    POL, SOP, EE, etc...
Columns:   CategoryID (PK), CategoryTitle, CategoryCode  (POL, SOP, EE, etc...)

VolunteerCategory:  One record for each volunteer + category
Columns: VolunteerID, CategoryID


VolunteerID | CategoryID
22 |  3   <=== ie Volunteer AA + POL
22 |  5   <=== ie Volunteer AA + EE
22 |  1   <=== ie Volunteer AA + SOP
12 |  3   <=== ie Volunteer BB+ POL
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

LVL 29

Assisted Solution

by:Pravin Asar
Pravin Asar earned 1000 total points
ID: 39257813
Here is simple example, which I think is efficient way to populate and set the checkboxes.

<!--- All Options ---->
<cfset fChkValues="POL,SOP,EE,ADMIN,TF,ANY"/>

<!--- Retrieved from user profile --->

<cfset chkValues="POL,ADMIN,EE"/>
<cfif #len(chkValues)#>
<cfoutput>For checkbox "chk1": <b>#chkvalues#</b></cfoutput>

<!--- Build the form --->
<cfform name="f1">

<!--- Loop over to populate the form --->
      For setting the checked value, use the GetCheckedFlag()
<cfloop list="#fChkValues#" index="vx">
<br/><cfinput type="checkbox" name="chk1" value="#vx#" checked="#GetCheckedFlag(chkValues,vx)#"/>#vx#</cfoutput>
<br/><cfinput type="submit" name="submit" value="submit"/>
function GetCheckedFlag(chklist,chkvalue) {
  if (ListFind(chklist,chkvalue) gt 0) { return "yes"; }
  return "no";
LVL 52

Accepted Solution

_agx_ earned 1000 total points
ID: 39257939
> <cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "SOP")>checked</cfif>>
> if (ListFind(chklist,chkvalue)

Essentially, that's exactly what the original code is doing already ...

@koila - Like I said, personally I recommend against storing lists. BUT your original code should've worked as is. Unless your "lists" contain extra values - perhaps spaces? Lists are extremely sensitive to differences.  Try trimming it or replacing spaces with an empty string.

<!--- add extra spaces deliberately to verify it works --->
<cfset DisplayCVITool.CMTEE_PREF = "  POL, SOP,   EE   ">
<cfset fixedValue = replace(DisplayCVITool.CMTEE_PREF, " ", "", "all")>
POL <input type="checkbox" name="CMTEE_PREF_NEW" value="POL"
        <cfif listFindNoCase(fixedValue, "POL")>checked</cfif>>
SOP <input type="checkbox" name="CMTEE_PREF_NEW" value="SOP"
        <cfif listFindNoCase(fixedValue, "SOP")>checked</cfif>>
EE  <input type="checkbox" name="CMTEE_PREF_NEW" value="EE"
        <cfif listFindNoCase(fixedValue, "EE")>checked</cfif>>

Open in new window


Author Comment

ID: 39297421
thank you please help me with my other questions.

Featured Post

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
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…

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