//this is in php
function msgbox($msg, $type)
{
if ($type == "alert")
{
// Simple alert window
?> <script language="JavaScript"> alert("<? echo $msg; ?>"); </script> <?
}
elseif ($type == "confirm")
{
// Enter 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.
What you are trying to accomplish can be created with Ajax, as long as the page is created on server side and then send to user, you cannot directly tamper $result variable as you intended. First grasp a reference of
AJAX
and how to use it..101 article on Ajax with jQuery (sitepoint.com)
Simple implementation of AJAX with jQuery and PHP
Client.html
And a delete.php script, which takes $_GET['title'] as parameter
Note, that this is just simplified, to show you, how a simple AJAX call can be done
You are using short tags, make sure that they are turned on from php.ini file otherwise php code won't execute in your code.
You cannot mix server-side code (PHP) with client-side code that way. For javascript to change PHP-state, you need to make a HTTP-call (AJAX is often used).
You need to read a PHP-tutorial and make sure you grasp the concepts.