...

View Full Version : Event Scope Problem



binaryWeapon
09-08-2008, 01:34 AM
I have a method of a class called add(). Within add() I set define an onkeyup event. But within the onkeyup event, I need to access class variables, but the this keyword no longer refers to the class. I need to be able to edit the variable as well. So my problem is that the code



add(){
element.onkeyup=function(){
this.errors='';
}
}
v=new validation();
v.add();


will get the error "this.errors is undefined".

How can I bind the this.errors parameter?

A1ien51
09-08-2008, 01:46 AM
Something like this:



var ref = this;
element.onkeyup=function(){
ref.errors='';
}


Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum