普通网友 2013-01-22 15:48
浏览 109
已采纳

PHP isset和javascript

I have been searching for a few days on how to do this and I have yet to find an example of what I am looking for. Am I looking for the wrong thing?

Here is what I am trying to accomplish using the following code, I am reading in my error code and creating a link out of the error code.

<p><h4>Errors Returned (if any): </h4> 
    <a href="https://www.mysite.com/test/search_form.php?query=<?php echo $ERRORCODE; ?>">
        <?php echo $ERRORCODE; ?>
    </a>
</p>

I am then posting this information to my search form (below):

<?php
if (isset($_GET['query']))
{
    echo "javascript... and such.";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Search - Test Site 2013</title>
  </head>
    <table border="0" cellpadding="10">
      <tr>
        <td>
          <img src="images/test.png">
        </td>
        <td>
          <h1>Search - Test Site 2013</h1>
        </td>
      </tr>
    </table>
<body>
    <form action="search.php" method="GET" name="errorsearch">
        Search by Error Code
        <input type="text" name="query" />
        <input type="submit" value="Search" name="search"/>
    </form>
</body>
</html>

I am using (isset($_GET['query'])) to check if the error code has been passed over in the URL. I am able to successfully display a message or something silly, but I would like to submit the form and check for the error code text BUT ONLY IF query has been set.

It is my understanding that Javascript can do this but I am unsure exactly what is needed. I was researching Javascript submit buttons and on-click events but I think this is the opposite of what I want. I just need JS to initiate the button click.

Can someone point me in the right direction?

  • 写回答

3条回答 默认 最新

  • doter1995 2013-01-22 15:55
    关注

    There are a number of different ways you could do this, but this question has already been answered elsewhere on this site. The answers here should help you: JavaScript code to stop form submission

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能