944,030 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 4176
  • ASP RSS
May 7th, 2007
0

how to get the values of checkboxes and delete them

Expand Post »
i want to get the checked checkboxes values to get deleted from the database.can u please help me in this ........................urgent.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pavsuri is offline Offline
1 posts
since May 2007
May 7th, 2007
0

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

Hi there,
have you tried to make this work?
well here the way do do this :
ASP :
ASP Syntax (Toggle Plain Text)
  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.
Reputation Points: 39
Solved Threads: 23
Junior Poster
katarey is offline Offline
167 posts
since Jul 2005
May 7th, 2007
0

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

Hi Again,

if above code not works so just replace

This Part :
ASP Syntax (Toggle Plain Text)
  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 :

ASP Syntax (Toggle Plain Text)
  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.
Reputation Points: 39
Solved Threads: 23
Junior Poster
katarey is offline Offline
167 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: alternative to inet control
Next Thread in ASP Forum Timeline: I want to make a search engine for my assignment ASP files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC