Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Programmatically typing into a textbox (KeyboardEvent)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michael Hofer  
View profile  
 More options Feb 14 2012, 12:05 pm
Newsgroups: mozilla.dev.tech.xul
From: Michael Hofer <dev-tech-...@erstes.ml1.net>
Date: Tue, 14 Feb 2012 18:05:55 +0100
Local: Tues, Feb 14 2012 12:05 pm
Subject: Programmatically typing into a textbox (KeyboardEvent)
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.