Look at this code (i didnt test it):
----[file.html]----
<script language='javascript'>
function ConfirmDelete()
{
if (confirm('Delete file?'))
{
return true;
}
else
{
return false;
}
}
</script>
<form method='post' name='file.php' onsubmit='return ConfirmDelete();'>
<input type='hidden' name='fileID' value='1'>
<input type='submit' name='delete' value='Delete file'>
</form>
----[file.php]----
<?php
if (isset($_POST["delete"]))
{
$sQuery = "delete from xxx where fileid=".$_POST["fileID"];
}
?>
Main Topics
Browse All Topics





by: suquiPosted on 2003-01-27 at 05:49:56ID: 7821133
This cannot work. When using javascript and PHP always remember that:
ript.php"; }
PHP is executed on the SERVER
Javascript is executed on the CLIENT
This means that all PHP is executed FIRST, while your page is being "assembled" on the server side. Then, once ALL PHP has been executed, the page is sent to the client, where the browser starts executing the javascript. At that point, PHP exists no more.
You are essentially executing ONLY PHP in the first part. The PHP "prepares" the future javascript of the page, deletes the sql record or whatever you have written in PHP and then sends the final page to the browser. At that point, you create the confirm, which essentially just shows one alert or another.
Basically, for javascript to control PHP results, execute the PHP in a hidden frame, as follows:
x=confirm("delete?")
if (x == true) {hidden.location="deletesc
"hidden" is an iframe width and height=0.
Good luck!