View Full Version : XHTML 1.0 Strict and moving divs..

03-17-2009, 12:21 AM

I've been making a site recently that relies mainly on javascript and has several movable divs. Until recently the doctype was html transitional, I've now changed it to XHTML 1.0 Strict and changed all the code to make it compliant, it validates fine, everything works as expected barring some dragable divs.

This has been driving me mad for a couple of days now, if I swap the doctype back everything is fine. Am I missing something fundamental here? Is the below code just not compatible with the strict xhtml doctype? Or is there something simple I can change?

Any help/advice much appreciated! :)
(curWid = the id of the elemnt I want to move)

var ie = document.all;
var nn6 = document.getElementById &&! document.all;

var isdrag = false;
var x, y;
var dobj;

function movemouse( e ) {
if( isdrag ) {
dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
dobj.style.top = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
return false;

function selectmouse( e ) {
var fobj = nn6 ? e.target : event.srcElement;
var topelement = nn6 ? "HTML" : "BODY";

while (fobj.tagName != topelement && fobj.className != "dragme") {
fobj = nn6 ? fobj.parentNode : fobj.parentElement;

if (fobj.className=="dragme") {
isdrag = true;
dobj = document.getElementById(curWid);
tx = parseInt(dobj.style.left+0);
ty = parseInt(dobj.style.top+0);
x = nn6 ? e.clientX : event.clientX;
y = nn6 ? e.clientY : event.clientY;
return false;

03-17-2009, 09:13 AM
(curWid = the id of the elemnt I want to move)
How about posting a link or the complete code?

03-17-2009, 11:47 AM
it rather an old code. A quick debug could be:

dobj.style.left = nn6 ? (tx + e.pageX - x)+'px' : tx + event.clientX - x;
dobj.style.top = nn6 ? (ty + e.pageY - y)+'px' : ty + event.clientY - y;
while (fobj.nodeName != topelement && fobj.className != "dragme") {
tx = parseInt(dobj.style.left,10);
ty = parseInt(dobj.style.top,10);

And, if embedded, make sure your javascript is nested within CDATA islands:

<script type="text/javascript">
... embedded code here ...

But I would have coded otherwise on detecting rather the e/event and pageX/clientX. And I would have considered the documentElement rather than HTML or BODY as the upmost element...

03-17-2009, 03:11 PM
Many thanks for the replies.

The first thing I tried was adding the 'px', it appears though I was adding it in the wrong way, I appreciate your guidance on this.

I think I understand what you mean regarding the upmost element, but I'm not sure what you mean about detecting 'e/event and pageX/clientX'. I should have really found out how to do this myself, it's questionable whether nabbing this bit of code has actually saved me any time and I still don't understand half of it. :o Anyway, once again many thanks for your help and I'll try and do some reading tonight on the other things you mentioned that might improve my way of doing this. :)