Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Checkboxes

Posted on 2014-12-12
9
Medium Priority
?
82 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
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 

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

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

715 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