Solved

Javascript confirm delete help

Posted on 2007-12-06
5
1,496 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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now