Solved

Checkboxes

Posted on 2014-12-12
9
72 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
 

Author Comment

by:lulu50
ID: 40496779
hmm,

something is still wrong, it loop again and again
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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 28

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

15 Experts available now in Live!

Get 1:1 Help Now