From: Andrew G. <an...@zo...> - 2003-08-22 05:54:51
|
Hello, I have had a problem with capturing keyboard events in HTMLTextBox. I want to execute some code when the Enter key is pressed in a textbox, but while the keyboard event handling in HTMLTextBox works quite well it doesn't allow me to find out which key was pressed. The getInnerHTML function in htmltextbox.js contains: this._inlineEvents+=' onkeypress="return htc._e(\'keypress\',this);" ' +' onkeyup="return htc._e(\'keyup\',this);" ' +' onkeydown="return htc._e(\'keyup\',this);" ' The event handlers are invoked with two arguments: a String that give the kind of event and a reference to the TextBox object. The event handler in my own code gets the reference to the object but this doesn't let me find out which key was pressed. I have worked around this problem in my own copy of DynAPI by adding the "event" object to the arguments passed to the event handler: this._inlineEvents+=' onkeypress="return htc._e(\'keypress\',this,event);" ' +' onkeyup="return htc._e(\'keyup\',this,event);" ' +' onkeydown="return htc._e(\'keyup\',this,event);" ' ... The _e function also needs to change from: p._e = function(evt,elm){ var rt = this._oldHCTBEvt(evt,elm); to p._e = function(evt,elm,arg){ var rt = this._oldHCTBEvt(evt,elm,arg); This allows my own event handler two receive two parameters: the object that raised the event and the event itself. May I suggest this change be made to the library? I'm hoping it won't cause any cross-browser portability problems. On a slightly different matter, while I was poking about in htmltextbox.js, I noticed that line 72 contained: if(this.getElm()) this.elm.readonly=(b)? 'readyonly':''; The 'readyonly' looks like a typo which should probably be fixed. regards Andrew Gillett ps. I'm using the latest version for DynAPI3 from CVS. |