Solved

Javascript confirm delete help

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 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

16 Experts available now in Live!

Get 1:1 Help Now