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>
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>