...

View Full Version : how to catch the enter key in a single input field form



NL_Fred
07-05-2004, 02:15 PM
Hello,

I've got a very simple form like:

<fieldset><legend>Search on name</legend>
<table class=body >
<form name="search" action="search.php" method="POST" >
<input type="hidden" name="action" value='name'>
<tr>
<td width=170 valign=center>Name</td>
<td width=480 valign=center>
<input size="20" maxlength="30" type="text" name="search_name" value="" ></td>
</tr>
<tr>
<td width=170 valign=center><input type="Submit" name="submit" value="Send"></td>
<td width=480 valign=center>&nbsp;</td>
</tr>
</form>
</table>
</fieldset>

I would like the enter key to work (Submit). If you fill out this form the enter key does not work. I have tried scripts that check for the enter key to be pressed. They work fine with me in textarea fields. But until now they do not work in a normal input field.

Does anyone know how to handle this I've tested it with ie6 on XP and ie5.x on Win98.

I only have this problem when I have a single field form. If i have a form with two input fields the enter key does generate a submit (as wanted).

jbot
07-05-2004, 03:17 PM
they should always work in normal text fields.

go to Google and see for yourself. type something - anything - into the search field and hit enter, and it'll submit the form. see! :thumbsup:

Willy Duitt
07-05-2004, 03:33 PM
One of the tricks I use to test what a form is passing is to use Google by changing the form action to google and the method to get. Google then prints out a nice little line of everything passed.

IE: The requested URL /?action=name&search_name=dddd was not found on this server.

jbot
07-05-2004, 03:38 PM
One of the tricks I use to test what a form is passing is to use Google by changing the form action to google and the method to get.

that's a neat trick. never thot of doing that before.

thanx for sharing the tip, m8. :D

NL_Fred
07-05-2004, 04:02 PM
Sure I know what should work, but what if it does not!!!!

If I have just one input field and no other fields in the form but just the submit, the enter does not work. If I have an other field in this form the enter does work!!! Strange?

B.t.w. Google also has a radiobutton field!!

Willy Duitt
07-05-2004, 04:08 PM
I just ran your codes and they work but in order for the enter key to work properly, there must be a submit button within the form also......

jbot
07-05-2004, 04:08 PM
Sure I know what should work, but what if it does not!!!!

If I have just one input field and no other fields in the form but just the submit, the enter does not work. If I have an other field in this form the enter does work!!! Strange?

yes, indeed. Google works even if there's nothing typed into it's single field.

curious.

NL_Fred
07-05-2004, 04:13 PM
What do I do wrong then. I have a submit button in my code

jbot
07-05-2004, 04:36 PM
Hello,
<input type="Submit" name="submit" value="Send"></td>


should be:

<input type="submit" name="submit" value="Send"></td>

jbot
07-05-2004, 04:39 PM
also,


<input type="hidden" name="action" value='name'>

might be better as:

<input type="hidden" name="my_action" value='name'>

NL_Fred
07-05-2004, 05:29 PM
I updated the "Submit" to "submit", but.... as expected that didn't change a bit. The submit button already worked so "Submit" was interpreted okay.

It has to be something else. :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum