Solved

Checkboxes

Posted on 2014-12-12
9
81 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
[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
  • 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 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