Handling enter key down event

  • Thread starter Thread starter RA
  • Start date Start date
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
 
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
 
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();
}
}
}
 
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.
 
Back
Top