469,593 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,593 developers. It's quick & easy.

Capturing Enter Key

I'm developing a website using visual studio .NET

I have a login form with a couple of textboxes and a login button. What I
want to do is capture the Enter key so that when the user presses Enter, it
will click the submit button.

I have searched the Internet for hours now trying to find out how to do it,
but any methods that I have seen do not work.

Can anyone help me do that?
Dec 29 '05 #1
3 1588
If your login button is just an <input type="submit" .../>, then I
would expect it to respond to enter automatically. If, however, you are
using ASP textbox controls, then problems seem to occur, particularly
on esoteric browsers. If you are using an asp:HtmlButton or
asp:HtmlInputButton, you could try using an asp:Button instead, as
that's more likely to work. If that doesn't help, I would try adding a
(client-side) onkeydown event that checks for character 13 (return),
and if it detects it, calls the form's submit method.

It'd be helpful if you could post the code for the page in question,
though [and perhaps say what are the sorts of methods that did not

Dec 29 '05 #2
Never mind!!! I found a way using Javascript
Dec 29 '05 #3
Well, there were too many things I had tried in order to capture the Enter
Key. In the end, I used this javascript:


if (document.layers)

document.onkeydown = function (evt)
var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) :

if (keyCode == 13)
return false;
return true;


It works like a charm.
Dec 30 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by jerrygarciuh | last post: by
4 posts views Thread by Vazz | last post: by
14 posts views Thread by Brent Burkart | last post: by
4 posts views Thread by Steve Wolfie | last post: by
4 posts views Thread by alien2_51 | last post: by
2 posts views Thread by Malt via AccessMonster.com | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.