Solved

Checkboxes

Posted on 2014-12-12
9
78 Views
Last Modified: 2014-12-17
Hi,

I have an update page, so, on that page I have a list of checkboxes.  I need to check the checkboses that are checked.


this is what I have so far.

<cfquery name="Select_DB" datasource="#dsn#" username="#dbID#" password="#dbPassword#">
		Select DBID as DID, DBName as DName
		From AppDatabase
        order by DBName ASC
	</cfquery>


Note: the output value for AppInformation.DBID is this: 4,3,7,1,6,10,5,2 


<cfset checkedList = "">

<cfloop index="kk" list="#valueList(AppInformation.DBID)#">
 <cfif listFind(checkedList,kk) eq 0> 
     <cfset checkedList = listAppend(checkedList,kk)>
 </cfif> 
</cfloop>


                       <cfloop index = "i" list = #checkedList#> 
                       <cfoutput query="Select_DB">
                       <cfdump var="#Select_DB.DID#">
                         <cfif #i# eq #Select_DB.DID#>
                         	<cfinput type="checkbox" checked="yes" name="Insert_DB" value="#Select_DB.DID#"><cfoutput>11111 - #Select_DB.DID#</cfoutput> <br>
                         <cfelse>
                    		<cfinput type="checkbox" checked="No" name="Insert_DB" value="#Select_DB.DID#"><cfoutput>22222 - #Select_DB.DID#</cfoutput> <br>
                         </cfif>
                         </cfoutput>
                       </cfloop>

Open in new window



Thank you,

My logic is off as usual
0
Comment
Question by:lulu50
  • 5
  • 3
9 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 40496604
I think you could use this for the CFIF, just check to see if the checkbox's value in on the list of all the checked IDs...

                         <cfif listFind(valueList(AppInformation.DBID),Select_DB.DID)>


like this..

                         <cfif listFind(valueList(AppInformation.DBID),Select_DB.DID)>
                               <cfinput type="checkbox" checked="yes" name="Insert_DB" value="#Select_DB.DID#"><cfoutput>11111 - #Select_DB.DID#</cfoutput> <br>
                         <cfelse>
                                <cfinput type="checkbox" checked="No" name="Insert_DB" value="#Select_DB.DID#"><cfoutput>22222 - #Select_DB.DID#</cfoutput> <br>
                         </cfif>
0
 

Author Comment

by:lulu50
ID: 40496653
just one checkbox is checked

don't I have to loop the query Select_DB?
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 40496666
Sorry, I don't think I included all the code.

Here it is again, I also added the variable "checkedList"  only so that valueList() would not have to be processed again and again in every loop...


                       <cfset checkedList = valueList(AppInformation.DBID)>
                       <cfoutput query="Select_DB">
                         <cfif listFind(checkedList,Select_DB.DID)>
                         	<cfinput type="checkbox" checked="yes" name="Insert_DB" value="#Select_DB.DID#"><cfoutput>11111 - #Select_DB.DID#</cfoutput> <br>
                         <cfelse>
                    		<cfinput type="checkbox" checked="No" name="Insert_DB" value="#Select_DB.DID#"><cfoutput>22222 - #Select_DB.DID#</cfoutput> <br>
                         </cfif>
                       </cfoutput>

Open in new window

0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

Author Comment

by:lulu50
ID: 40496779
hmm,

something is still wrong, it loop again and again
0
 

Author Comment

by:lulu50
ID: 40496827
This works but I need to put the name how can I do this :

     	<cfset checkedList = valueList(AppInformation.DBID)>
      	<cfset checkList = valueList(Select_DB.DID)>   // How can I put the name "Select_DB.DName"
        
    	<cfloop index="i" list="#checkList#"> 
   			<cfif listFind(checkedList,i)>
     			<cfinput type="checkbox" checked="yes" name="Insert_DB" value="#i#"><cfoutput>11111 - #Select_DB.DName#</cfoutput><br>
     		<cfelse>
       			<cfinput type="checkbox" checked="no" name="Insert_DB" value="#i#"><cfoutput>222 - #Select_DB.DName#</cfoutput><br>
	   		</cfif>
		</cfloop>

Open in new window

0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 40496852
Ok, something is off.  I might have made a wrong assumption.

1.  The query SELECT_DB is a list of *ALL*   "DB_names"  
2.  Which DB_names are already checked is found in a query called "AppInformation"  (this query is not included in your posts).

If those two things are true, then you shouldbe able to do this..

    <cfquery name="Select_DB" datasource="#dsn#" username="#dbID#" password="#dbPassword#">
		Select DBID as DID, DBName as DName
		From AppDatabase
        order by DBName ASC
	</cfquery>

    <cfset checkedList = valueList(AppInformation.DBID)>
    <cfoutput query="Select_DB">
      <cfif listFind(checkedList,Select_DB.DID)>
      	<cfinput type="checkbox" checked="yes" name="Insert_DB" value="#Select_DB.DID#"><cfoutput>11111 - #Select_DB.DID#</cfoutput> <br>
      <cfelse>
 		<cfinput type="checkbox" checked="No" name="Insert_DB" value="#Select_DB.DID#"><cfoutput>22222 - #Select_DB.DID#</cfoutput> <br>
      </cfif>
    </cfoutput>

Open in new window


You should see only one checkbox for every DB Name.
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 40499610
You could simplify your code by use of ListContains. This returns 0 if not found in a list.


<cfoutput query="Select_DB">
            <cfinput type="checkbox" checked="#ListContains(checkedList,Select_DB.DID)#" name="Insert_DB" value="#Select_DB.DID#">11111 - #Select_DB.DID#<br/>
</cfoutput>



You may find following working example useful:

<cfset entity = QueryNew ("entityid, entity","integer,varchar")/>
<cfset tt=QueryAddRow(entity,1 )/>
<cfset tt=QuerySetCell (entity, "entityid", 1)/>
<cfset tt=QuerySetCell (entity, "entity", "entity 1")/>
<cfset tt=QueryAddRow(entity,1 )/>
<cfset tt=QuerySetCell (entity, "entityid", 2)/>
<cfset tt=QuerySetCell (entity, "entity", "entity 2")/>
<cfset tt=QueryAddRow(entity,1 )/>
<cfset tt=QuerySetCell (entity, "entityid", 3)/>
<cfset tt=QuerySetCell (entity, "entity", "entity 3")/>
<cfset tt=QueryAddRow(entity,1 )/>
<cfset tt=QuerySetCell (entity, "entityid", 4)/>
<cfset tt=QuerySetCell (entity, "entity", "entity 4")/>
<cfdump var="#entity#"/>
<cfset checkedList = "1,3,4"/>
<cfform name="f1">
      <cfoutput query="entity">
            <br/><cfinput type="checkbox" name="mychk" checked="#ListContains(checkedList,entityid)#" value="#entityid#">#entity#</cfinput>
      </cfoutput>
</cfform>
0
 

Author Comment

by:lulu50
ID: 40504588
gdemaria Thank you!!!1

It works great!!!!!!!!

Wishing you and your family a happy holiday!!!!!! :-)
0
 

Author Closing Comment

by:lulu50
ID: 40504589
Thank you
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mixing cold fusion headers and footers with PHP body 6 70
code conversion assistance required 1 34
coldfusion, javascript onclick url update 4 65
coldfusion cfloop help 6 36
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 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