Solved

Javascript confirm delete help

Posted on 2007-12-06
5
1,499 Views
Last Modified: 2012-06-21
Hi,
Can anyone please tell me how I can get a confirmation popup box when clicking on a delete link.  
For example if the delete link is clicked a popup to appear asking are you sure you want to delete ad <?php echo $adid; ?>" then if yes is selected to go to to del_ad.php?adnum=<?php echo $adid; ?>

<a href="del_ad.php?adnum=<?php echo $adid; ?>" onClick="confirmDelete();">Delete</a>

Thanks in advance for your assistance.
0
Comment
Question by:sabecs
5 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 20419438

<a href="" onClick="confirmDelete('del_ad.php?adnum=<?php echo $adid; ?>','Are you sure you want to delete ?'); return false;">Delete</a>
<script>
 
function confirmDelete(varURL,varMSG){
 
	question = confirm(varMSG)
 
	if (question != "0"){
		
		if(varURL =="") {
		
			document.submit();
			
		}else {
		
			window.location=varURL
			
		}
	}
}
</script>

Open in new window

0
 
LVL 9

Expert Comment

by:waygood
ID: 20419447
Try this


function confirmation(question)
{
	return confirm(question + " (OK = Yes   Cancel = No)");
}
 
<form action="del_ad.php?adnum=<?php echo $adid; ?>" method="get" onSubmit="return confirmation('This will delete the Album. Are you sure?');"><input type="submit" value="DELETE"/></form>

Open in new window

0
 
LVL 11

Expert Comment

by:raj3060
ID: 20419448
Something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
<title>Confirm Delete</title>
<SCRIPT>
function confirmDelete(){
	var conf = confirm('Are you sure you want to delete!!!\r\nClick OK to proceed, or Cancel')
	if(conf)
	  return true;
	else
	  return false;
}
</SCRIPT>
</head>
<body>
<input type='button' name='Delete' value="Delete" onclick="return confirmDelete() "/>
</body>
</html>

Open in new window

0
 
LVL 9

Expert Comment

by:waygood
ID: 20419461
sorry forgot to put the function in the script tags.
0
 

Author Closing Comment

by:sabecs
ID: 31413134
Thanks steelseth12, its perfect.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question