stick_branch
06-20-2009, 03:15 PM
hi all,
i have to attach an event to the body, and in all eventuality it will be doing something completely different, but for the time being it is just bringing up an alert box for testing, but i'm attaching an event to the document onkeypress.
var test = new testFunction();
function testFunction(){
this.attachListener = function(){
if(document.addEventListener){
document.addEventListener('keypress',function(){test.onKeyPress(event)},false);
}
else if(document.attachEvent){
document.attachEvent(onkeypress,function(){test.onKeyPress(event)})
}
else{
//old way
}
}
this.onKeyPress = function(e){
if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
alert(keynum);
}
}
but event returns undefined. Not sure why, as it's the only way I know how to get what key was pressed... but it's inaccessible
thanks for your help
i have to attach an event to the body, and in all eventuality it will be doing something completely different, but for the time being it is just bringing up an alert box for testing, but i'm attaching an event to the document onkeypress.
var test = new testFunction();
function testFunction(){
this.attachListener = function(){
if(document.addEventListener){
document.addEventListener('keypress',function(){test.onKeyPress(event)},false);
}
else if(document.attachEvent){
document.attachEvent(onkeypress,function(){test.onKeyPress(event)})
}
else{
//old way
}
}
this.onKeyPress = function(e){
if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
alert(keynum);
}
}
but event returns undefined. Not sure why, as it's the only way I know how to get what key was pressed... but it's inaccessible
thanks for your help