> onmousemove="if(draggable==1){this.style.left=event.x-25+'px';this.style.to?p=event.y-25+'px';}"
> onmouseup="draggable=0;this.style.position='static';"></div>
[quoted text clipped - 3 lines]
> I have written what I would expect to do the same thing in other browsers (I
> replaced event.x/event.y with event.layerX/event.layerY). Here is that code:
[cross-posting removed]
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Why are you using XHTML transitional for a new document?
??? Standards compliance, maybe...?
> And why use XHTML at all if you are going to serve this as HTML?
???

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
I am using XHTML because the place where I will be using these techniques is
in an ASP.NET page, which is created using that header. The x/y properties
are only used in the IE version; both pageX/Y and clientX/Y gave an alert
saying they were undefined, so I did not know what else to use for IE. Is
there something else that works in IE? I would like to skip the drag & drop,
but my boss won't let me.

Signature
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/
On Oct 16, 9:13 pm, "Nathan Sokalski" <njsokal...@hotmail.com> wrote:
> I have the following code which allows you to drag a div in IE, and have
> it
> then move back to it's natural position when you release the mouse button:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Why are you using XHTML transitional for a new document? And why use
XHTML at all if you are going to serve this as HTML?
> <html>
> <head><script type="text/javascript">var draggable=0;</script></head>
[quoted text clipped - 3 lines]
> <div id="div2" style="width:300px;height:300px;background-color:green;"
> onmousedown="draggable=1;this.style.position='absolute';this.style.left=event.x-25+'px';this.style.top=event.y-25+'px';"
Don't use the x/y properties. They are non-standard and unreliable.
And what is the significance of 25?
> onmousemove="if(draggable==1){this.style.left=event.x-25+'px';this.style.top=event.y-25+'px';}"
> onmouseup="draggable=0;this.style.position='static';"></div>
[quoted text clipped - 5 lines]
> replaced event.x/event.y with event.layerX/event.layerY). Here is that
> code:
Using layerX/layerY is also a bad idea. Use pageX/Y if defined and
clientX/Y otherwise. For the latter pair you must add the scroll
position of the document. You will find that most browsers support
one pair or the other (or both.) If neither is defined, you should
skip the drag and drop operation as the results will be unpredictable.
Randy Webb - 17 Oct 2007 20:50 GMT
Nathan Sokalski said the following on 10/17/2007 12:12 PM:
> I am using XHTML because the place where I will be using these techniques is
> in an ASP.NET page, which is created using that header.
Nice to know Microsoft products generate a document that a Microsoft
browser can't handle.

Signature
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
David Mark - 18 Oct 2007 01:28 GMT
> I am using XHTML because the place where I will be using these techniques is
> in an ASP.NET page, which is created using that header. The x/y properties
That seems an odd choice for a Microsoft product.
> are only used in the IE version; both pageX/Y and clientX/Y gave an alert
> saying they were undefined, so I did not know what else to use for IE. Is
The clientX/Y properties are certainly present in IE.
> there something else that works in IE? I would like to skip the drag & drop,
> but my boss won't let me.
There is some very simple cross-browser drag and drop code in this
project:
http://code.google.com/p/niceshowcase/
You will see that it only uses pageX/Y and clientX/Y.