You can't request more than 20 challenges without solving them. Your previous challenges were flushed.

Synthetic Events

May 6, 2002, 11:00 PM —  ITworld — 

In JavaScript, pretty much everything you do with respect to your
graphical user interface (GUI) has to do with detecting and reacting to
events. When the user clicks a button, to cite a popular example, the
click is represented as an event object of the click type and is passed
to whatever event handler (if any) is assigned to react to events of
that kind. Events bubble upwards through the Document Object Model (DOM)
-- from, say, a button to its form to its document to its browser -- and
event handlers may react to it at more than one level, if you want to
set things up that way.

The newer versions of the DOM, as implemented in Microsoft Internet
Explorer 6, allow you to use JavaScript to define and execute synthetic
events. Synthetic events are event objects that are created ex nihilo by
the JavaScript programmer, as opposed to "real" events that come into
being as a result of an action within the browser window. Synthetic
events can, for example, simulate a selection from a drop-down list box
followed by a click on a particular button, or a click on a particular
region followed by a drag between two pairs of coordinates.

Synthetic events aren't helpful when creating auto-running
demonstrations, since the events appear to take place for no reason
(i.e., the mouse pointer doesn't move) and, unless you put in delay
statements, the events occur in such quick succession that you can't
tell what's happening. Rather, synthetic events are nice for creating
test drivers that verify the behavior of interfaces. You can set up your
application so that a single button click triggers a whole series of
events, which will be run in an absolutely consistent way. This would
enable you to adjust your application to behave as required in response
to certain user behavior.

To create a synthetic event, you use the createEvent() method of the
Document object.

var e = new Event;
e = document.createEvent("MouseEvents");

The createEvent() method takes any of several strings as arguments;
"MouseEvents" describes a set of events associated with the mouse
pointer. A DOM reference will give you a full roster of legal
arguments.

When you've created an event, you need to initialize it before you turn
it loose. Here's how to do that:

e.initEvent("click", true, false);

The "click" argument is one that's significant to the "MouseEvents" set
mentioned earlier -- again, consult that reference. The two Boolean
values refer to whether the event bubbles up through the DOM and whether
the event may be canceled with the preventDefault() method.

When you've configured your event, you can apply it to an element in the
local DOM this way:

document.myForm.myButton.dispatchEvent(e);

That simulates a click on the DOM element called myButton.

» posted by ITworld staff

ITworld

Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
peer-to-peer

jfruh
Apple syncing patent can't come soon enough

pasmith
New Twitter features borrow from 3rd party clients

Esther Schindler
Open Source Changes the Software Acquisition Process

mikelgan
How to set up continuous podcast play on the new iTunes

David Strom
Five important Windows 7 mobility features

sjvn
Guard your Wi-Fi for your own sake                        

Sandra Henry-Stocker
Grepping on Whole Words

 

Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace