指定一个JavaScript确认框的结果PHP变量 [英] Assigning the result of a JavaScript confirm box to a PHP variable

查看:120
本文介绍了指定一个JavaScript确认框的结果PHP变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//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..

问题是, $结果不是从确认框我想读的值,因为如果子句不被执行,程序流程是怎么回事哪里会去没有if子句。

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.

推荐答案

您不能混用服务器端code(PHP)与客户端$ C C这样$。 对于JavaScript来改变PHP的状态,你需要做一个HTTP调用(AJAX经常使用)。

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).

您需要阅读PHP的教程,并确保你掌握的概念。

You need to read a PHP-tutorial and make sure you grasp the concepts.

这篇关于指定一个JavaScript确认框的结果PHP变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆