Handling enter key down event

R

RA

Hi

I have a few server side text box and a server side button. The problem is
that I want to be able to control the enter key click while in the text box
or anyother place in the web form.

Thanks,
Ron
 
A

Alvin

one way is to use plain old javascript. it's probably the most efficient
because the keyboard click event happens on the client. try trapping for
keycode = 13 i believe
 
C

Chris Lane

I have only verified the following script to work with
Netscape 7.0 and IE 6.0.

function checkKey(e)
{
//alert(navigator.appName);
var intKeyCode = 0;
if (navigator.appName == "Microsoft Internet
Explorer")
{
if (window.event.keyCode == 13)
{
btnVerify_onclick();
}
}
if (navigator.appName == "Netscape")
{
//alert(e.which);
intKeyCode = e.which;
if (intKeyCode == 13)
{
btnVerify_onclick();
}
}
}
 
C

Chris Lane

I forgot to say to add that script inside a script block
inside the <HEAD> section of your page. So it would look
like this:
<HEAD>
<Script ID=clientEventHandlersJS LANGUAGE="JavaScript">
<!--Hide Script
/*
document.onkeypress = checkKey;
function checkKey(e)
{
//alert(navigator.appName);
var intKeyCode = 0;
if (navigator.appName == "Microsoft Internet
Explorer")
{
if (window.event.keyCode == 13)
{
btnVerify_onclick();
}
}
if (navigator.appName == "Netscape")
{
//alert(e.which);
intKeyCode = e.which;
if (intKeyCode == 13)
{
btnVerify_onclick();
}
}
}
//End Hiding-->
</Script>
</HEAD>

If Enter was pressed you could then submit the form or
validate data client side and then submit the form.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top