Programmatically typing into a textbox (KeyboardEvent)

Michael Hofer <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xpfe
Message-ID <[email protected]>
Hello,

I want to programmatically type into a xul textbox (xulrunner 2.0). 
While the following code does trigger the "not canceled"-alert, it 
doesn't change the contents of the textbox:

XUL:
-------------------------------------

   <textbox id="testbox"/>

JS (triggered on button command);
-------------------------------------

   var test_el = document.getElementById("testbox");
   var evt = document.createEvent("KeyboardEvent");
   evt.initKeyEvent("keypress", true, true, null, false, false, false, 
false, 65, 0); //65 is character 'a'

   var canceled = !test_el.dispatchEvent(evt);
   if(canceled) {
     // A handler called preventDefault
     alert("canceled");
   } else {
     // None of the handlers called preventDefault
     alert("not canceled");
   }


A similar example with MouseEvents (click) triggering a checkbox works 
fine for me, but I can't get the KeyboardEvent working (entering text in 
the textbox). Any help is greatly appreciated.

regards,
Michael
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.