forcom Posted July 7, 2009 Share Posted July 7, 2009 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 https://forums.phpfreaks.com/topic/165017-solved-form-submit-in-textbox-when-enter-key-hit/ Share on other sites More sharing options...
p2grace Posted July 7, 2009 Share Posted July 7, 2009 If you wrap it in a form then the enter will automatically act as a submit. If you need help post your html code so we can edit. Link to comment https://forums.phpfreaks.com/topic/165017-solved-form-submit-in-textbox-when-enter-key-hit/#findComment-870206 Share on other sites More sharing options...
forcom Posted July 7, 2009 Author Share Posted July 7, 2009 <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 https://forums.phpfreaks.com/topic/165017-solved-form-submit-in-textbox-when-enter-key-hit/#findComment-870364 Share on other sites More sharing options...
p2grace Posted July 7, 2009 Share Posted July 7, 2009 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 https://forums.phpfreaks.com/topic/165017-solved-form-submit-in-textbox-when-enter-key-hit/#findComment-870394 Share on other sites More sharing options...
forcom Posted July 7, 2009 Author Share Posted July 7, 2009 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 https://forums.phpfreaks.com/topic/165017-solved-form-submit-in-textbox-when-enter-key-hit/#findComment-870606 Share on other sites More sharing options...
p2grace Posted July 7, 2009 Share Posted July 7, 2009 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 https://forums.phpfreaks.com/topic/165017-solved-form-submit-in-textbox-when-enter-key-hit/#findComment-870610 Share on other sites More sharing options...
forcom Posted July 7, 2009 Author Share Posted July 7, 2009 Thanks for the information. I got it to work 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 https://forums.phpfreaks.com/topic/165017-solved-form-submit-in-textbox-when-enter-key-hit/#findComment-870634 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.