PDA

View Full Version : passing key pressed in function


pranav
02-26-2004, 05:04 AM
How do I pass the key that is pressed in a javascript function .

I'm using :
<input type=text name="a" size=10 onkeypress="check()">

I want to pass the key pressed in the function check .

Thanks

Willy Duitt
02-26-2004, 05:18 AM
Use event.keyCode.

eg:
javascript:void(document.body.onkeypress=function(){alert(event.keyCode)});

.....Willy

pranav
02-26-2004, 06:40 AM
Thanks for reply.

But I require another thing .

I need the following :

function check()
{

}

<input type="text" name="a" size=20 onkeypress = "check();">

I want to acess the event.keyCode in function check.

Thanks

Willy Duitt
02-26-2004, 06:44 AM
The answer is right there in my post.
function check(){alert(event.keyCode)}

.....Willy

pranav
02-26-2004, 07:00 AM
Dear friend ,

Thanks for replying . But , the problem is that it's not working with Mozilla/Galeon browsers .

Is there any solution for that ?

Thanks.

Willy Duitt
02-26-2004, 07:20 AM
You can try looking here (http://www.w3.org/2002/09/tests/keys.html) and here (http://www10.brinkster.com/A1ien51/Scripts/KeyCode.htm).

.....Willy