Microsoft HomeproductssearchsupportshopWrite Us   Microsoft Home
Magazine
 |  Community
 |  Workshop
 |  Tools & Samples
 |  Training
 |  Site Info

Workshop  |  DHTML, HTML & CSS

ondragstart Event


This document describes technologies available in the Internet Explorer 5 Beta. While we encourage you to evaluate these features and to send us your feedback, please note that these features are subject to change.

Fires on the source object when the user first starts to drag a text selection or selected object.

Syntax

Inline HTML<ELEMENT ondragstart = "handler" ... >All platforms
Event propertyobject.ondragstart = handlerJScript (compatible with ECMA 262 language specification) only
Named script<SCRIPT FOR=object EVENT=ondragstart>Internet Explorer only

Remarks

BubblesYes
CancelsYes
To invoke Drag the selected text or object.
Default action Calls the associated event handler.

The ondragstart event is the first to fire when a drag procedure is initiated. It is essential to every drag operation, yet is just one of several source events in the data-transfer object model. Source events use the setData method of the dataTransfer object to provide information about data being transferred. The list of source events includes:

Event Object Properties

Although event handlers in the DHTML Object Model do not receive parameters directly, the handler can query the event object for data.

Event Object Properties

altKeyRetrieves the current state of the ALT key.
cancelBubbleSets or retrieves whether the current event should bubble up the hierarchy of event handlers.
clientXRetrieves the x-coordinate of the position of the cursor when the mouse is clicked, relative to the size of the client area of the window but excluding window decorations or scroll bars.
clientYReturns the y-coordinate of the position of the cursor when the mouse is clicked, relative to the size of the client area of the window but excluding window decorations or scroll bars.
ctrlKeyRetrieves the state of the CTRL key.
dataTransferProvides access to predefined clipboard formats for use in data transfer operations.
offsetXRetrieves the horizontal coordinate of the mouse's position relative to the object firing the event.
offsetYRetrieves the vertical coordinate of the mouse's position relative to the object firing the event.
returnValueSets or retrieves the return value from the event.
screenXRetrieves the horizontal position of the mouse, in pixels, relative to the user's screen.
screenYRetrieves the vertical position of the mouse, in pixels, relative to the user's screen.
srcElementRetrieves the object that fired the event.
typeRetrieves the event name from the event object.
xReturns the horizontal position of the mouse when the event fires.
yReturns the vertical position of the mouse when the event fires.

Example

The first sample detects the tagName of the object from which the ondragstart event has originated. The second shows the order of event firing for drag-and-drop events.

Sample Code

The sample detects the tagName of the object from which the ondragstart event has originated. Because the event bubbles, it can be handled at the BODY level.

<BODY ondragstart="alert(event.srcElement.tagName)">
  <INPUT TYPE=text VALUE="Select and drag this text">
  <SPAN>Select and drag this text</SPAN>
  <TEXTAREA>Select and drag this text</TEXTAREA>
</BODY>

This feature requires Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

The following example illustrates when each event fires during a drag-and-drop operation.

<HEAD>
<SCRIPT>
function ShowResults()
var oNewOption;            

// Code for dynamically adding options to a select.

function ShowResults()
{                // Information about the events 
                 // and what object fired them.
  arg = event.type + "  fired by  " + event.srcElement.id;  
  oNewOption = new Option(); 
  oNewOption.text = arg;
  oResults.add(oNewOption,0);
}
</SCRIPT>
</HEAD>
<BODY>
<P>Source events are wired up to this text box.</P>
<INPUT ID=txtDragOrigin VALUE="Text to Drag"
    ondragstart="ShowResults()"
    ondrag="ShowResults()"
    ondragend="ShowResults()"
>
<P>Target events are bound to this text box.</P>
<INPUT ID=txtDragDestination VALUE="Drag Destination"
    ondragenter="ShowResults()"
    ondragover="ShowResults()"
    ondragleave="ShowResults()"
    ondrop="ShowResults()"
>
<SELECT ID=oResults SIZE=30>
  <OPTION>List of Events Fired
</SELECT>
</BODY>

This feature requires Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

See Also

Data Transfer Overview, onbeforecut, onbeforecopy, oncut, oncopy, ondrag, ondragend


Does this content meet your programming needs? Write us!

Back to topBack to top

© 1998 Microsoft Corporation. All rights reserved. Terms of use.

 

Magazine Home
Ask Jane
DHTML Dude
Extreme XML
For Starters
More or Hess
Servin' It Up
Site Lights
Web Men Talking
Member Community Home
Benefits: Freebies & Discounts
Benefits: Promote Your Site
Benefits: Connect with Your Peers
Benefits at a Glance
Online Special-Interest Groups
Your Membership
SBN Stores
Join Now
Workshop Home
Essentials
Content & Component Delivery
Component Development
Data Access & Databases
Design
DHTML, HTML & CSS
Extensible Markup Language (XML)
Languages & Development Tools
Messaging & Collaboration
Networking, Protocols & Data Formats
Reusing Browser Technology
Security & Cryptography
Server Technologies
Streaming & Interactive Media
Web Content Management
Workshop Index
Tools & Samples Home
Tools
Samples, Headers, Libs
Images
Sounds
Style Sheets
Web Fonts
Training Home
SBN Live Seminars
SBN Live Chats
Courses
Peer Support
CD-ROM Training
Books & Training Kits
Certification
SBN Home
New to SBN?
What's New on SBN
Site Map
Site Search
Glossary
Write Us
About This Site