Drag and drop in a table using dynamic html?

  • Thread starter Thread starter Ana S
  • Start date Start date
A

Ana S

Guest
I created a drag and drop functions for a smiley image.
It works fine but not if i put it in a row of a table
<tr></tr> or <tr><td> </td></tr>
I cannot drag it at all if it's put inside the table.
How can i get it to work when it's inside the table??? I am trying to figure out how to do a drag of a row out of a table and into a recycle bin image but have been unsuccessful so i am now trying to just give the appearance of it working by having an image inside the row and being able to drag it out of the table to a recycle bin and delete the row.

Here's my test code:


<html>
<head>
<style>
img
{
position:absolute;
}
</style>

<script type="text/javascript">
document.onmousedown=coordinates;
document.onmouseup=mouseup;

function coordinates(e)
{
if (e == null) { e = window.event;}
var sender = (typeof( window.event ) != "undefined" ) ? e.srcElement : e.target;

if (sender.id=="moveMe")
{
mouseover=true;
pleft=parseInt(movMeId.style.left);
ptop=parseInt(movMeId.style.top);
xcoor=e.clientX;
ycoor=e.clientY;
document.onmousemove=moveImage;
return false;
}
else { return false; }
}

function moveImage(e)
{
if (e == null) { e = window.event;}
movMeId.style.left=pleft+e.clientX-xcoor+"px";
movMeId.style.top=ptop+e.clientY-ycoor+"px";
return false;
}

function mouseup(e)
{
document.onmousemove=null;
}

</script>
</head>
<body>

<img id="moveMe2" src="smiley.gif" width="32" height="32" />
<p>Drag and drop the image</p>

<script type="text/javascript">
//The movable image
movMeId=document.getElementById("moveMe2");
//image starting location
movMeId.style.top="75px";
movMeId.style.left="75px";
</script>
<table id="myTable" border="1">
<tr>

<td>

<img id="moveMe" src="smiley.gif" width="32" height="32" />
Row1 cell1

</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
<tr>
<td>Row3 cell1</td>
<td>Row3 cell2</td>
</tr>
</table>

</body>
</html>
 
Back
Top