Solved

How do you display a Checked button.

Posted on 2013-06-13
6
189 Views
Last Modified: 2013-07-03
I have the field CMTEE_PREF_NEW
Varchar(50)

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

<cfoutput>#DisplayCVIToolvolunteer.CMTEE_PREF_NEW#</cfoutput>

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.

<p><br>
            <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>
          </p>
          <table border="0" cellspacing="0" cellpadding="0" width="100%" class="qtable">
            <tr>
              <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" 
value="POL"
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "POL")>checked</cfif>>
                &nbsp;
                <label>Policy setting committees (POL)</label>
                <br>
                <input type="checkbox" name="CMTEE_PREF_NEW" id="CMTEE_PREF2" 
value="SOP"
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "SOP")>checked</cfif>>
                &nbsp;
                <label>Standard of practice setting committees (SOP)</label>
                <br>
                <input type="checkbox" name="CMTEE_PREF_NEW" id="CMTEE_PREF3" 
value="EE"
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "EE")>checked</cfif>>
                &nbsp;
                <label>
                Committees related to education and eligibility issues <em>(EE)</em></
                label><br>
                <input type="checkbox" name="CMTEE_PREF_NEW" id="CMTEE_PREF4" 
value="ADMIN"
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "ADMIN")>checked</cfif>>
                &nbsp;
                <label>Administrative committees such as Finance or Elections <em>(ADMIN)</em></label>
                <br>
                <input type="checkbox" name="CMTEE_PREF_NEW" id="CMTEE_PREF5" 
value="TF"
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "TF")>checked</cfif>>
                &nbsp;
                <label>Task Forces (typically short term commitment) <em>(TF)</em></label>
                <br>
                <input type="checkbox" name="CMTEE_PREF_NEW" id="CMTEE_PREF6" 
value="ANY"
<cfif listFindNoCase(DisplayCVITool.CMTEE_PREF, "ANY")>checked</cfif>>
                &nbsp;
                <label>Doesn’t matter, I just want to volunteer. <em>(ANY)</em></label></td>
            </tr>
          </table>

Open in new window

SQL-Table-data.jpg
reading-yes.jpg
display-data.jpg
0
Comment
Question by:koila
  • 3
  • 2
6 Comments
 
LVL 52

Expert Comment

by:_agx_
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">
<form>
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>>
</form>
0
 
LVL 4

Author Comment

by:koila
ID: 39248071
Hello Agx,

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


thank you,
0
 
LVL 52

Expert Comment

by:_agx_
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

Example:

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
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 28

Assisted Solution

by:Pravin Asar
Pravin Asar earned 250 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>
</cfif>

<!--- 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">
<cfoutput>
<br/><cfinput type="checkbox" name="chk1" value="#vx#" checked="#GetCheckedFlag(chkValues,vx)#"/>#vx#</cfoutput>
</cfloop>
<br/><cfinput type="submit" name="submit" value="submit"/>
</cfform>
<cfscript>
function GetCheckedFlag(chklist,chkvalue) {
  if (ListFind(chklist,chkvalue) gt 0) { return "yes"; }
  return "no";
}
</cfscript>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 250 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")>
<form>
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>>
</form> 

Open in new window

0
 
LVL 4

Author Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Status: 500, The value returned from the get_score function is not of type query 3 44
On Submit return to same spot 7 85
coldfusion, jQuery help 25 87
REReplaceNoCase help 1 18
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

24 Experts available now in Live!

Get 1:1 Help Now