//this is in php.
function msgbox($msg, $type)
{
if ($type == "alert")
{
// Simple alert window
?> <script language="JavaScript"> alert("<? echo $msg; ?>"); </script> <?
}
elseif ($type == "confirm")
{
// Ent开发者_如何学JAVAer Confirm Code Here and assign the $result variable for use
// Should include "OK" and "Cancel" buttons.
?>
<script language="JavaScript">
if (confirm("<? echo $msg; ?>"))
{
<? $result == "ok"; ?>
}
else
{
<? $result == "cancel"; ?>
}
</script>
<?
}
}
if ($page_title->exists())
{msgbox("page exists,do you want to delete", "confirm");
}
if ($result == "ok")
//code..
The problem is that $result
is not reading the value from the confirm box i think because the if clause is not being executed and the program flow is going where it would go without the if clause.
You have to understand when is your PHP and JavaScript code executed. First the server runs your PHP code. This generates HTML output, that gets passed to your browser and the browser executes the JavaScript code. This means that when you run confirm()
in JavaScript, your PHP code is already finished (and probably serving another request).
You will need to rethink the user interaction.
(Btw, JSP means Java Servlet Pages, not JavaScript)
精彩评论