douhushen3241 2015-09-25 07:20
浏览 36
已采纳

我想检查用户单击按钮时php字符串代码和html属性代码是否相等

   <script language="javascript" type="text/javascript">
        function validate5(str)   
        {  
            var myvar = <?php echo json_encode($code);?>

            if (str.valueOf()===myvar.valueOf())  
            {  
              <?php include_once("view/ok.php");
                 $this->model->insertCustomer(); ?>
                 return true;
              }
            else{
                alert("Wrong Key ...Try Again");  
            return false;
            }
        }
    </script>
</head>
<body>
    <form >
    <h3> Insert Code: </h3> <input type="text"  id="code" />
    <button type="button" onclick="return validate5(code)">Confirm</button>
    </form>
    </body>

I've declared the $code correctly i just want to redirect the user to ok.php if the text user entered matches with the $code is code is correct or stay on same page. is it possible to it the way i'm trying to do? if not please suggest some different way

  • 写回答

1条回答 默认 最新

  • doushadu0901 2015-09-25 07:49
    关注

    Try this:

    <script language="javascript" type="text/javascript">
        function validate5()   
        {  
            var myvar = <?php echo json_encode($code);?>
            var str = document.getElementById('code').value;
    
            if (str==myvar)  
            {  
              window.location.href="/view/ok.php";
                 return true;
              }
            else{
                alert("Wrong Key ...Try Again");  
                return false;
            }
        }
    </script>
    </head>
    <body>
    <form >
    <h3> Insert Code: </h3> <input type="text"  id="code" />
    <button type="button" onclick="return validate5();">Confirm</button>
    </form>
    </body>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程