User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 392,090 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,939 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Views: 1877 | Replies: 2
Reply
Join Date: May 2007
Posts: 1
Reputation: pavsuri is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pavsuri pavsuri is offline Offline
Newbie Poster

Solution how to get the values of checkboxes and delete them

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 143
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 15
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

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

  #2  
May 7th, 2007
Hi there,
have you tried to make this work?
well here the way do do this :
ASP :
<%
'declare variables
Dim connstring, cn, rs
'Connection String
connString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/conn/db1.mdb")
Sub OpenDataBase()
	Set cn = Server.CreateObject("ADODB.CONNECTION")
	cn.open connstring
End Sub
	'Open Database 
		OpenDataBase()
	'Create Recordset
		set rs = Server.CreateObject("ADODB.Recordset")
		sql = "Select * from users"
		rs.Open sql, cn
'If Form Submit this part will Execute		
if Request.Form("Delete") = "Delete" then	
	'Get All Checked checkbox
	checks = Request.Form("chkBox")
	'checkbox array 	
	check_a = split(checks, ",")		
	'SQL	
	str = ""
	str = "Delete from users where "
	'Adding checked checkbox values to Sql string
	for i = 0 to ubound(check_a)
		if i = 0 then
			str = str & "uid = "& check_a(i)
		else
			str = str & " AND uid = "& check_a(i)
		end if
	next
	'Open Database 
	 OpenDataBase()
		'Execute SQL String
		cn.execute(str)	
		Response.Write "Record Deleted!"
%>
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 7:48 pm.
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 143
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 15
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

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

  #3  
May 7th, 2007
Hi Again,

if above code not works so just replace

This Part :
	for i = 0 to ubound(check_a)
		if i = 0 then
			str = str & "uid = "& check_a(i)
		else
			str = str & " AND uid = "& check_a(i)
		end if
	next

With :

	for i = 0 to ubound(check_a)
		if i = 0 then
			str = str & "uid = "& check_a(i)
		else
			str = str & " OR uid = "& check_a(i)
		end if
	next

Thanks
Rahul
Last edited by katarey : May 7th, 2007 at 8:38 pm.
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP Forum

All times are GMT -4. The time now is 12:36 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC