Choopernickel
07-14-2003, 08:23 PM
So I'm finally trying to turn the type-ahead combobox that GlennGV wrote and I augmented into an easy-to-instantiate class, but I'm running into trouble.
(code is attached, including example instantiation)
How is it best to assign event handlers to elements using class-based scripting? I've got the constructor function accepting two arguments: the ID of the element which will be the type-ahead combobox, and the name of the variable (object) that's created to hold the functions and properties.
When no arguments are passed to the constructor, I return; because at that point I'm just setting up the prototype. I create the methods, set up the prototype with the argument-free constructor, assign the prototype properties, and assign the methods to the prototype as the script loads. On page load, the object is created with a call to the constructor.
The constructor assigns the event handlers to the select element, but as the handlers themselves are methods of the object created by the constructor, I have to use a latent-assignment method (hence the reason I'm passing in the name of the variable that is the object).
Relevant bit of code:
function GVECD_Combo(anElement, theVarContainer) {
...
this.element = anElement;
// event handlers
this.element.onkeydown = theVarContainer + ".elementKeydown()";
this.element.onfocus = theVarContainer + ".elementFocus()";
this.element.onclick = theVarContainer + ".updateIndex()";
this.element.onblur = theVarContainer + ".updateIndex()";
}
This isn't working. When I alert() the select element's onfocus method, it shows me the right text, but it means nothing to the script engine.
You all know I don't wish to use eval() - but right now I'm seeing only that and one other option: DOM2Events by Chris Nott, which I like but would prefer to not use because I really don't want to build a class dependent upon another class.
Any help? TIA, ecd.
(code is attached, including example instantiation)
How is it best to assign event handlers to elements using class-based scripting? I've got the constructor function accepting two arguments: the ID of the element which will be the type-ahead combobox, and the name of the variable (object) that's created to hold the functions and properties.
When no arguments are passed to the constructor, I return; because at that point I'm just setting up the prototype. I create the methods, set up the prototype with the argument-free constructor, assign the prototype properties, and assign the methods to the prototype as the script loads. On page load, the object is created with a call to the constructor.
The constructor assigns the event handlers to the select element, but as the handlers themselves are methods of the object created by the constructor, I have to use a latent-assignment method (hence the reason I'm passing in the name of the variable that is the object).
Relevant bit of code:
function GVECD_Combo(anElement, theVarContainer) {
...
this.element = anElement;
// event handlers
this.element.onkeydown = theVarContainer + ".elementKeydown()";
this.element.onfocus = theVarContainer + ".elementFocus()";
this.element.onclick = theVarContainer + ".updateIndex()";
this.element.onblur = theVarContainer + ".updateIndex()";
}
This isn't working. When I alert() the select element's onfocus method, it shows me the right text, but it means nothing to the script engine.
You all know I don't wish to use eval() - but right now I'm seeing only that and one other option: DOM2Events by Chris Nott, which I like but would prefer to not use because I really don't want to build a class dependent upon another class.
Any help? TIA, ecd.