...

View Full Version : Confirmation Box onClick



Candrias77
01-16-2003, 09:07 AM
I have added a simple link to a page. Since this link causes an item to be deleted from the database, I would like a simple warning box to pop up with the option to cancel or confirm the deletion.

I need some kind of onClick function for my <A> that opens a warning box and when OK is clicked the url is opened and if the Cancel button is clicked, nothing happens.

I am sure that this must be relatively simple, it's just that I have never done this kind of thing before.

Thanks

head8k
01-16-2003, 12:24 PM
Try this:

<script language="javascript" type="text/javascript">
<!--
function sure(){
var sure = confirm("Are you sure?\r\n\r\nThis will permanantly delete from the database!");
if(sure) location.replace('delete_page.asp');
}
//-->
</script>

and call it like this:

<a href="javascript:void(0)" onclick="sure()">delete item?</a>

Good luck :thumbsup:

Candrias77
01-16-2003, 07:32 PM
Thanks, this code is good but is there another way of writing it so that I can still specify the url of the confirmation page. Within the <a tag> rather than within the java function.

Because of the way the page is programmed, this would make things much easier.

Thanks for your help.

beetle
01-16-2003, 07:36 PM
Originally posted by Candrias77
Thanks, this code is good but is there another way of writing it so that I can still specify the url of the confirmation page. Within the <a tag> rather than within the java function.

Because of the way the page is programmed, this would make things much easier.

Thanks for your help. Yes!
<a href="delete_page.asp" onclick="return confirm( 'Are you sure?\r\n\r\nThis will permanantly delete from the database!' );">delete item?</a>Or, done as a function
function confirmDelete()
{
return confirm( 'Are you sure?\r\n\r\nThis will permanantly delete from the database!' );
}

<a href="delete_page.asp" onclick="return confirmDelete();">delete item?</a>

Candrias77
01-16-2003, 07:47 PM
Perfect, thank you very much.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum