EasyCFM.COM ColdFusion Forums / Coding Help! / Checkbox to mark for deletion.

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Checkbox to mark for deletion. -- page: 1 2

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

IPGRuss
03-23-2005 @ 7:04 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 206
Joined: Feb 2005

Hey all,

I'm working on a site that has a list of links that will load from a database.  Next to each link I want a checkbox that will mark the link for deletion.  Once the user clicks the delete button it will only remove the checked items.  Here's my pseudo code:

cfoutput query="get_links"

input type=checkbox
#url_description#

/cfoutput

That, in theory will create the list of links with a checkbox to the left of them, but how do I go about processing the checked boxes for removal?

Thanks!

maquiladoras
03-23-2005 @ 7:19 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2073
Joined: Dec 2002

just google "SQL Delete Multiple Rows"
remember, forms only pass values of effected items
ie check boxes, unchecked check boxes are not passed
buy you will want to use the SQL Function "DELETE" and the SQL Operator "IN()"

-
"There is no justice, There is Just Us"
-

waterswing
03-23-2005 @ 7:25 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 51
Joined: Feb 2005

First you need to name your checkboxes and give them a value:

<input type="checkbox" name="id" value="#url_id#">

Then on the action page you loop over form.id and remove from the db acordingly.

Maybe it would even work to loop within one query like this (maybe someone can confirm or laugh at me):

<cfquery name="delete" datasource="yourdsn">
<cfloop list="form.id" index="i">
DELETE FROM tablename
WHERE url_id = #i#;
</cfloop>
</cfquery>

Best regards
Trond Ulseth
Waterswing Studio
www.waterswing.com

kene
03-23-2005 @ 11:04 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 180
Joined: Sep 2003

Here is some sample code used in an app I've worked on. It is used to delete all records marked on the previous page.
<cfset count=0>
<cfloop index="fName" list="#form.FieldNames#">
     <cfif left(fName, 6) IS "chkBtn">
          <cfset chkValue="#RemoveChars(fName, 1, 6)#">     
          <cfquery name="delete" datasource="#myDSN#">
          UPDATE Content
        SET Removed=1
          WHERE RecordID=<cfqueryparam value="#chkValue#" cfsqltype="cf_sql_int">
          </cfquery>
          <cfset count=(count +1)> <!--- find out how many records were processed --->
     </cfif>
</cfloop>


Each of the check boxes is given the name chkBtn and the ID value of the record is attached after that. So I take off the chkBtn portion to return the ID value as the chkValue I want to delete.

HTH

maquiladoras
03-23-2005 @ 11:22 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2073
Joined: Dec 2002

.......dont over complicate the matter

you have a check box that you just name the same
and then it passes a comma delimited set of results

so you have something like this

formtest.cfm
<CFIF IsDefined('form.action')>
<font color="red">Your form values are
<cfoutput>#form.mycheckbox#</cfoutput></font>
<br>
</CFIF>
<br>
<br>

<form name="MultipleTest" action="formtest.cfm" method="POST">
<input type="checkbox" name="mycheckbox" value="1">1<br/>
<input type="checkbox" name="mycheckbox" value="2">2<br/>
<input type="checkbox" name="mycheckbox" value="3">3<br/>
<input type="checkbox" name="mycheckbox" value="4">4<br/>
<input type="checkbox" name="mycheckbox" value="5">5<br/>
<input type="checkbox" name="mycheckbox" value="6">6<br/>
<input type="submit" name="submit" value="submit">
<input type="hidden" name="action" value="go">
</form>


Basically you keep the checkboxes named the same and then what ever you tick, gets passed

then you just do

DELETE FROM myTable WHERE column IN (#form.mycheckbox#)



-
"There is no justice, There is Just Us"
-

IPGRuss
03-23-2005 @ 12:28 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 206
Joined: Feb 2005

It doens't seem to be working, here's my code:

nav_loader.cfm (referring page)

<html>
<head>
<title>Nav Loader</title>
<link rel="stylesheet" type="text/css" href="styles/nav_loader.css" />
<script>
function createLink(){
window.open("createlink.cfm","","width=350,height=125,status=0,scrollbars=0,resizable=0")
}
function deleteLink(){
window.open("deletelink$.cfm","","width=350,height=75,status=0,scrollbars=0,resizable=0")
}
</script>
</head>

<body bgcolor="e6e6e6" topmargin="5" leftmargin="2" rightmargin="2">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><a href="javascript:createLink()"><img src="styles/default/sml_icons/addlink.gif" border="0" width="16" alt="Create Link"></a></td>
<td align="center"><a href="javascript:deleteLink()"><img src="styles/default/sml_icons/delete.gif" border="0" width="16" alt="Delete Links"></a></td>
<td align="center"><a href="#"><img src="styles/default/sml_icons/refresh.gif" border="0" width="16" alt="Refresh List"></a></td>
<td align="center"><a href="#"><img src="styles/default/sml_icons/help.gif" border="0" width="16" alt="Help"></a></td>
</tr>
<tr>
<td colspan="4">&nbsp;</td>
</tr>
<cfquery name="getLinks" datasource="Intranet">
     SELECT *
     FROM Links
     WHERE authUser = '#getAuthUser()#'
</cfquery>
<cfoutput query="getLinks">
<tr>
<td colspan="4"><input type="checkbox" name="checkbox" value="#urlID#"><a href="#url#" target="_blank">#urlDescription#</a></td>
</tr>
</cfoutput>
</table>
</body>
</html>


deletelink$.cfm

<html>
<head>
<title>Delete A Link</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="styles/nav_loader.css" />
</head>

<body background="styles/default/dropback.gif">
<cfquery name="creatLink" datasource="intranet">
     DELETE FROM Links WHERE urlID EQ (#form.deleteLink#)
</cfquery>
<br>
<center>
<p class="info">Link(s) deleted successfully.  Use the refresh button to update your list.</p>
<form>
<input type=button value="Close" onClick="javascript:window.close();">
</form>
</center>
</body>
</html>



maquiladoras
03-23-2005 @ 12:30 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2073
Joined: Dec 2002

please try to read what im telling you

firstly its
DELETE FROM table WHERE column IN (#form.var#)

in this case you put
DELETE FROM table WHERE column EQ (#form.deletelink#)

but your checkbox is named checkbox, not datelink,
so change it to #form.checkbox#

-
"There is no justice, There is Just Us"
-

This message was edited by maquiladoras on 3-23-05 @ 12:32 PM

IPGRuss
03-23-2005 @ 1:35 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 206
Joined: Feb 2005

I made those corrections and it gives me Element CHECKBOX is undefined in FORM.

maquiladoras
03-23-2005 @ 1:39 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2073
Joined: Dec 2002

you need to reference the name of your checkbox
and you need to make sure that your checkbox is inside teh <form></form>

the element xyz not found just means the form doesnt contain

<input type="formtype" name="xyz">

thats all

-
"There is no justice, There is Just Us"
-

IPGRuss
03-23-2005 @ 1:47 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 206
Joined: Feb 2005

It is, here's the code:

<form action="nav_loader.cfm" method="post">
<cfoutput query="getLinks">
<tr>
<td colspan="4">
<input type="checkbox" name="chkDelete" value="#urlID#"><a href="#url#" target="">#urlDescription#</a></td>
</tr>
</cfoutput>
</form>


PAGE: 1 2

Website Designed and Developed by Pablo Varando.