Jump to content

[SOLVED] Form submit in textbox when enter key hit


forcom

Recommended Posts

Hello all,

 

How can I get my form textbox to hold the values when user hits enter key. I want enter key to be same as hitting the submit button.

 

if(isset($_POST['search']) || ? ){

//Submit button hit or Enter button hit

}

Link to comment
Share on other sites



<table cellpadding="0" cellspacing="0" width="954" border="0" height="258" bgcolor="FFFFFF">
<tr><td colspan="2">
<center><br>
<form method="post">
<table cellpadding="0" cellspacing="0" width="380" height="30">
        <tr>
                         <td width="297" valign="middle">
                <input type="text" name="gosearch" size="40">
                </td>
                <td width="108">
                <input type="submit" value="Go Search" name="search">
                </td>
                </tr></form>
</table>

Link to comment
Share on other sites

Try this, you had the form ending before the table.  I also converted your width and valign to proper css.

 

<form method="post" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" width="380" height="30">
        <tr>
			<td style="width: 297px; vertical-align: middle;"><input type="text" name="gosearch" size="40" /></td>
			<td style="width: 108px; vertical-align: middle;"><input type="submit" value="Go Search" name="search" /></td>
		</tr>
</table>
</form>

Link to comment
Share on other sites

I tried and still having the same problem. When I type in a word in the text area and click on go search button everything works but if I just type in the word and press the enter key on the keyboard I don`t get any results.

 

How can I code this so when user hits the enter key on the keyboard.

 

if(isset($_POST['search']) ){

//Submit button hit or Enter button hit

}


Link to comment
Share on other sites

The script below works on enter, I just tested it.  If this doesn't work for you then please post your code so we can see the issue.

 

<?php
if(isset($_POST['gosearch'])){
  echo $_POST['gosearch'];
}
?>
<html>
<head>
</head>
<body>
<form method="post" enctype="multipart/form-data">
   <table cellpadding="0" cellspacing="0" width="380" height="30">
           <tr>
            <td style="width: 297px; vertical-align: middle;"><input type="text" name="gosearch" size="40" /></td>
            <td style="width: 108px; vertical-align: middle;"><input type="submit" value="Go Search" name="search" /></td>
         </tr>
   </table>
</form>
</body>
</html>

Link to comment
Share on other sites

Thanks for the information. I got it to work :D

I change code around that you submited. I remove input submit name and change text area name to keywords. Thanks for the help

 

if(isset($_POST['keywords'])){

//it works

}

 

<form method="post" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" width="380" height="30">
        <tr>
			<td style="width: 297px; vertical-align: middle;"><input type="text" name="keywords" size="40"/></td>
			<td style="width: 108px; vertical-align: middle;"><input type="submit" value="Go Search" /></td>
		</tr>
</table>
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.