Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validation before deleting a record

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi,

I have built a small app to remove records from a table, it all works fine. The problem i have come across, is what if the user clicks delete and then decides that they do not want to delete the record. At the moment you click the image and the row goes with no warning.

I would like an alert box with something like "Are you sure you want to delete this" where the user can select "yes" or "no"

Here is a snippet of the code in case anyone can help out, i have tried javascript alerts but i can't cancel the action even if i click no. It's just a <a href with and image that snds a query string to a dynamic.asp page.

Thanks for any help.

Code:
 	<tr>
		<td bgcolor="#cccccc"><a href="TechSupport.asp?typ=update&uniqueid=<% =(oRs("uniqueid")) %>&edituser=<% =Request.QueryString("user") %>"><img src="images/edit.gif" border="0" /></a></td>
		<td bgcolor="#cccccc"><%=(oRs("createuser"))%></td>
		<td bgcolor="#cccccc"><%=(oRs("createtime"))%></td>
		<td bgcolor="#cccccc"><%=(oRs("subject"))%></td>
		<td bgcolor="#cccccc"><%=(oRs("notes"))%></td>
		<td bgcolor="#cccccc"><a href="dynamic.asp?typ=delete&uniqueid=<% =(oRs("uniqueid")) %>" onClick="BeSure()"><img src="images/delete.gif" border="0" /></a></td>
	</tr>
 
Try confirm() in javascript. That should provide for you what you need.

------------------------------------------------------------------------------------------------------------------------
"As for the bureacratic, politically-correct, mollycoddling, asinine, Romper Room antics of...clients and management, just read up on Dilbert. It's not funny - it's a training manual."
- Mike
 
That prompts me to confirm but even if you cancel it still executes my delete code.

Thanks for trying
 
I think you need to add a return false; command if the user clicks no.

------------------------------------------------------------------------------------------------------------------------
"As for the bureacratic, politically-correct, mollycoddling, asinine, Romper Room antics of...clients and management, just read up on Dilbert. It's not funny - it's a training manual."
- Mike
 
Untested, but this might work:


<script TYPE="text/javascript">
<!--
function confirmation() {
var answer = confirm("You sure you want to delete this record?")
if (answer){
alert("Record deleted")
window.location = "}
else{
alert("Record not deleted")
}
}
//-->
</script>

<form>
<input type="button" onclick="confirmation()" value="Delete record?">
</form>


where " is replaced with "dynamic.asp?typ=delete&uniqueid=<% =(oRs("uniqueid")) %>"

Except that I don't know how to escpe those quotes around uniqueid and I'm sure it will throw an error if you don't. Either \" or single quotes, maybe.

HTH.
 
Ok, first, I'd probably change that from an anchor href to a submit button (which you could then cancel). I'm not sure you can actually do that with a link like that. Then, to modify BigRed's code somewhat...
Code:
<script TYPE="text/javascript">
<!--
function confirmation() {
var answer = confirm("You sure you want to delete this record?")
if (answer){
alert("Record deleted")
window.location =  [COLOR=red]"dynamic.asp?typ=delete&uniqueid=<% =(oRs("uniqueid")) %>";
return true;[/color]
}
else{
[COLOR=red]return false;[/color]
}
}
//-->
</script>

------------------------------------------------------------------------------------------------------------------------
"As for the bureacratic, politically-correct, mollycoddling, asinine, Romper Room antics of...clients and management, just read up on Dilbert. It's not funny - it's a training manual."
- Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top