how to get the values of checkboxes and delete them

Reply

Join Date: May 2007
Posts: 1
Reputation: pavsuri is an unknown quantity at this point 
Solved Threads: 0
pavsuri pavsuri is offline Offline
Newbie Poster

how to get the values of checkboxes and delete them

 
0
  #1
May 7th, 2007
i want to get the checked checkboxes values to get deleted from the database.can u please help me in this ........................urgent.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 154
Reputation: katarey is an unknown quantity at this point 
Solved Threads: 20
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Re: how to get the values of checkboxes and delete them

 
0
  #2
May 7th, 2007
Hi there,
have you tried to make this work?
well here the way do do this :
ASP :
  1. <%
  2. 'declare variables
  3. Dim connstring, cn, rs
  4. 'Connection String
  5. connString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/conn/db1.mdb")
  6. Sub OpenDataBase()
  7. Set cn = Server.CreateObject("ADODB.CONNECTION")
  8. cn.open connstring
  9. End Sub
  10. 'Open Database
  11. OpenDataBase()
  12. 'Create Recordset
  13. set rs = Server.CreateObject("ADODB.Recordset")
  14. sql = "Select * from users"
  15. rs.Open sql, cn
  16. 'If Form Submit this part will Execute
  17. if Request.Form("Delete") = "Delete" then
  18. 'Get All Checked checkbox
  19. checks = Request.Form("chkBox")
  20. 'checkbox array
  21. check_a = split(checks, ",")
  22. 'SQL
  23. str = ""
  24. str = "Delete from users where "
  25. 'Adding checked checkbox values to Sql string
  26. for i = 0 to ubound(check_a)
  27. if i = 0 then
  28. str = str & "uid = "& check_a(i)
  29. else
  30. str = str & " AND uid = "& check_a(i)
  31. end if
  32. next
  33. 'Open Database
  34. OpenDataBase()
  35. 'Execute SQL String
  36. cn.execute(str)
  37. Response.Write "Record Deleted!"
  38. %>
HTML :
[HTML]
<%else%>
<!-- Form Not Submited Yet-->
<form action="CheckBox.asp" method="post" name="form1" id="form1">
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<td>Delete</td>
<td>User Id</td>
<td>User Name</td>
</tr>
<%
c=0
do while not rs.eof
c=c+1
%>
<tr>
<td><input type="checkbox" name="chkBox" value="<%=rs("uid")%>"></td>
<td><%=rs("uid")%></td>
<td><%=rs("username")%></td>
</tr>
<%
rs.movenext
loop
%>
<tr>
<td colspan="3"><input name="Delete" type="submit" value="Delete" /></td>
</table>
</form>
<%end if%>
[/HTML]

I hope this will useful for you and others!

Regards,
Rahul Dev Katarey
Last edited by katarey; May 7th, 2007 at 8:48 pm.
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 154
Reputation: katarey is an unknown quantity at this point 
Solved Threads: 20
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Re: how to get the values of checkboxes and delete them

 
0
  #3
May 7th, 2007
Hi Again,

if above code not works so just replace

This Part :
  1. for i = 0 to ubound(check_a)
  2. if i = 0 then
  3. str = str & "uid = "& check_a(i)
  4. else
  5. str = str & " AND uid = "& check_a(i)
  6. end if
  7. next

With :

  1. for i = 0 to ubound(check_a)
  2. if i = 0 then
  3. str = str & "uid = "& check_a(i)
  4. else
  5. str = str & " OR uid = "& check_a(i)
  6. end if
  7. next

Thanks
Rahul
Last edited by katarey; May 7th, 2007 at 9:38 pm.
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC