How to make a Textbox Submit
I have a search box and a buttion. the user is currently entering text and hitting the search button. But I want to add another function so that instead of clicking the search button, people can press Enter to search. How can i do this?
Here's my sample code:
<form method="post" action="">
<input id="search" name="search" type="text" />
<input id="search_btn" name="search_btn" type="submit" />
</form>
Thanks in advance
+2
a source to share
3 answers
You can do this using the following methods.
<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>
0
a source to share
<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];
}
}
?>
-1
a source to share