PDA

View Full Version : Yes/No Prompt before database update...


wzrd
09-21-2004, 06:26 PM
I didn't know whether to put this here or the Javascript forum

I have an ASP page that loads up, reads in Form variables from the previous page and deletes records in an SQL database based upon those variables.

The trick being, I want to be able to prompt the user, "Are you sure?". I tried doing this with an

var stay=confirm("Are you sure you wish to delete these records? If you say yes, you will not be able to undo these actions.")
if (!stay)
window.location="recordData.asp"


and having the ASP code that actually deleted the records, after that on the page. Of course, the problem being that the ASP code runs before anything else so by the time they click Ok/Cancel, it's already been done.


So, I'm wondering, how do I go about this? Do I need to have a page in between the Form page and the actual deletion page? Is there not something simplier? I come from Thick client programming most recently so have to have a whole other page seems much overkill and much extra work.


Thanks for any help you can offer.

A1ien51
09-21-2004, 06:55 PM
Two ways, You can post the information t a new page, then delete from that page

OR

You can add the confirm to the button using the onclick property or the form with the onsubmit property depending on how you are implementing this on the page.

Eric

wzrd
09-21-2004, 07:28 PM
Two ways, You can post the information t a new page, then delete from that page

OR

You can add the confirm to the button using the onclick property or the form with the onsubmit property depending on how you are implementing this on the page.

Eric
Would give me a bit further details on the second option? Thanks much.

A1ien51
09-21-2004, 07:48 PM
examples:


<input type="submit" onclick="return confirm('Are you sure?')" value="qwerty">


or

<form onsubmit="return confirm('Are you sure?')">



Eric

NEExt
09-21-2004, 08:00 PM
Any way to add an onclick confirm box to all <a> tags with a certain class?

A1ien51
09-21-2004, 08:26 PM
It would be alot better to handle this on the server side adding it to the elements, but this is what you asked for:


<html>
<head>
<script>
function AddHandlers(){
theLink = document.getElementsByTagName("a");
for(i=0;i<theLink.length;i++){
if(theLink[i].className == "blah")theLink[i].onclick = new Function("return confirm('asdf');");
}
}
</script>
</head>
<body onload="AddHandlers()">
<form>
<a href="http://www.google.com" class="blah">google</a><br/>
<a href="http://www.google.com" class="blah">google</a><br/>
<a href="http://www.google.com" class="blah">google</a><br/>
<a href="http://www.google.com" class="blah">google</a><br/>
<a href="http://www.google.com" class="blah">google</a><br/>
<a href="http://www.google.com" class="blah">google</a><br/>
<a href="http://www.google.com" class="blah">google</a><br/>
<a href="http://www.google.com" class="blah">google</a><br/>
<a href="http://www.google.com" class="blah">google</a><br/>
<a href="http://www.google.com" class="blah">google</a><br/>
<a href="http://www.google.com" class="argh">google - no</a><br/>
</form>
</body>
</html>



Eric

NEExt
09-21-2004, 08:45 PM
Awesome :)

I create all the delete links server side. When clicked it goes to a delete page and deletes the particular record that was clicked. Your JS just makes it a bit safer before I've had my coffee.

Thanks again!