Help - Search - Member List - Calendar
Full Version: Confirming a delete
WorkTheWeb Forums > Web Hosting Help > PHP Help
Support our Sponsors!
noe0729
I am working on an admin tool and I want to confirm a delete with a javascript confirm box but the script I am using will not let me use the php variables in the target url.
CODE

<script language="javascript">
<!-- Hide from non-JavaScript Browsers
function ConfirmChoice()
{
answer = confirm("Really Delete?");
if (answer !=0)
{
 location = "index.php?page=NewsUpdater&page2=Delete&date=$date&subject=$subject";
}
}
//Done Hiding-->
</script>


Then I call this javascript with the following code
CODE

echo "
<a href='#' onclick='ConfirmChoice(); return false;'>Delete</a>";


When I click delete it asks for the confirm but then does not delete it. I know it has to do with the php variables in the url. I have dug through numerous forums and websites on this subject but have not found a way to work this out.

Any thoughts/ideas?
phpfreak
You could do the same thing without defining a function though smile.gif

CODE
<a onclick="if ( !window.confirm( 'Are you sure you want to DELETE THIS?' ) ) { return false; }" href="/URL_TO_DELETE">Delete</a>


Just pass in your variables into the /URL_TO_DELETE such as /news.php?cmd=delete&news_article=3

noe0729
QUOTE(phpfreak @ Mar 6 2005, 10:57 AM)
You could do the same thing without defining a function though smile.gif

CODE
<a onclick="if ( !window.confirm( 'Are you sure you want to DELETE THIS?' ) ) { return false; }" href="/URL_TO_DELETE">Delete</a>


Just pass in your variables into the /URL_TO_DELETE such as /news.php?cmd=delete&news_article=3
*


I ended up having to use backslashes so I could use double quotes in order to get the javascript embeded into the echo statement. Thanks for the info!
phpfreak
QUOTE(noe0729 @ Mar 6 2005, 11:46 AM)
I ended up having to use backslashes so I could use double quotes in order to get the javascript embeded into the echo statement. Thanks for the info!
*



That's the correct way to do it! Or, you could echo in single quotes and backslash the single quotes smile.gif

PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.