Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript confirm delete help

Posted on 2007-12-06
5
Medium Priority
?
1,505 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

670 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