Solved

Javascript confirm delete help

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
html input 8 42
Uploading a CSV Data Import via PHP & MySql 3 29
issue with DB import 1 17
JavaScript Sort Ordering and Choice Limiting 5 17
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to count occurrences of each item in an array.
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 …

807 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