Solved

Checkboxes

Posted on 2014-12-12
9
79 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

739 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