Hitting the enter key

A

Andy G

I have a login page w/ a few buttons on it. When the user types in their
username and password and hits the "Enter" key the applications runs the on
click event for another button on the page. I don't think tab control has
much to do with this. I need it so whenever someone hits the enter key it
needs to fire the "Login" button. The login button is defined as an HTML
Input control and all the other button is an ASP button (I'm sure this has
something to do with it)

Thanks
 
K

Ken Dopierala Jr.

Hi,

Here is how I do it:

My <body> tag looks like this:

<body MS_POSITIONING="FlowLayout" onkeypress="CheckSubmit();">

Then my CheckSubmit() routine looks like this:

<script language="javascript">
function CheckSubmit() {
if (event.keyCode == 13) {
document.getElementById("btnLogin").focus();
}
}
</script>

Everytime a key is pressed it calls the CheckSubmit() routine. If the
keycode is 13 (Enter), then it sets focus to the btnLogin control, which in
turn gets fired by letting the event bubble. Remember to change btnLogin to
whatever is the id of your button. Good luck! Ken.
 
A

Andy G

WOW! That is how to reply to a post...to the point, quick fix. Myself and
my clients would like to thank you Ken.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top