Php 如何提交文本框

Php 如何提交文本框,php,html,Php,Html,我有一个搜索框和一个按钮。当前,用户输入一些文本并按下搜索按钮。但是我想添加另一个功能,人们可以点击回车键进行搜索,而不是点击搜索按钮。我该怎么做 以下是我的代码示例: <form method="post" action=""> <input id="search" name="search" type="text" /> <input id="search_btn" name="search_btn" type="submit" />

我有一个搜索框和一个按钮。当前,用户输入一些文本并按下搜索按钮。但是我想添加另一个功能,人们可以点击回车键进行搜索,而不是点击搜索按钮。我该怎么做

以下是我的代码示例:

<form method="post" action="">

     <input id="search" name="search" type="text" />
     <input id="search_btn" name="search_btn" type="submit" />

</form>


提前感谢

按“回车”键将提交大多数没有hocus pocus的表单。

您可以使用以下方法进行提交

<script type="text/javascript">
  function submitenter(myfield,e)
  {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13)
    {
        myfield.form.submit();
        return false;
    }
    else
     return true;
  }

</script>

<form method="post" action="">

     <input id="search" name="search" type="text" :onKeyPress=>"return submitenter(this, event);"/>
     <input id="search_btn" name="search_btn" type="submit"  />

</form>

功能提交人(myfield,e)
{
var键码;
如果(window.event)keycode=window.event.keycode;
如果(e)keycode=e,则为else;
否则返回true;
如果(键代码==13)
{
myfield.form.submit();
返回false;
}
其他的
返回true;
}
“返回提交人(此事件);”/>

在大多数浏览器中,在非多行文本框中按enter键将提交关联的表单。是的,如果存在提交按钮(这就是为什么表单中的某个地方通常有一个默认行为的不可见提交按钮)-1表示无效语法、应用不好的事件模型和完全冗余的方法
<form method="POST" action="<?php $_SERVER['PHP_SELF'];?>">
<input type='text' name='text1' value='' size='30'>
<input type='submit' name='search' value='Search'>
</form>
<?php
include("connect.php");
mysql_select_db("example",$con);

if(isset($_POST['search'])){
$text=$_POST['text1'];

$result=mysql_query("SELECT * FROM example_tbl WHERE inputdata LIKE '$text'");
While($row=mysql_fetch_array($result)){
echo $row[0]."".$row[1]."".$row[2];
}
}
?>