...

View Full Version : onmouseup event in NS 6



markivs
04-25-2003, 05:28 PM
This is a NS6 related question. I drag a div and drop it on a table row. When I drop the div I want to find out which row I drop that div on.

How do I do that ? Right now with my code'onmouseup' event always returns the id of the div instead of id of the row I dropped on.

Please take a look at the code. You can copy it and test it too if you want.

Your help will be greatly appreciated.

Thanks.
Mark

<html>
<head><title></title><style>
.dragDiv {position: absolute;}
#dragOne {border: 1px solid gray;}
</style>
<script>
var dragElement;

function getDraggableElement (target) {
do
if (target.className == 'dragDiv')
return target;
while ((target = target.parentNode));
return null;
}

function dragStart (e) {
dragElement = getDraggableElement (e.target);
if (dragElement) {
document.onmousemove = dragOn;
document.onmouseup = dragEnd;
}
}

function dragOn (e) {
dragElement.style.left = e.clientX + 'px';
dragElement.style.top = e.clientY + 'px';
}

function dragEnd (evt) {
window.alert(evt.target.id);
document.onmousemove = null;
document.onmouseup = null;
dragElement = null;
}

document.onmousedown = dragStart;

</script>
</head>
<body>
<div id="dragOne" class="dragDiv">This is the dragable text</div>

<table id="tableOne" align="center" border="2">
<tr id="rowOne">
<td width="200"><div> Row One </div></td>
</tr>

<tr id="rowTwo">
<td width="200"><div> Row Two </div></td>
</tr>
</table>
</body>
</html>

Roy Sinclair
04-25-2003, 08:32 PM
Try setting up a global onmousemove event handler, one of the items in the event object should always be what element the mouse is currently over, if you jsut store that in a global variable in the event handler it should point to the drop item when the onmouseup event occurs.

markivs
04-25-2003, 11:13 PM
I am not sure if I understand you right.
I moved the document.onmouseup outside the dragStart function. But still it dosen't seem to work.

I also tried to assign it to a global variable.
var mouseUpVar = document.onmouseup
And I was alerting mouseUpVar in the dragEnd method. But that dosen't work either.

Can you pls give me an example ?

Thanks.
Mark

markivs
04-28-2003, 04:09 AM
PLEASE !! someone help me on this. It's pretty urgent.

Mark



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum