I have a situation where I am clicking (mouse down) at some position (say x1, y1) on an image and the moving the mouse and releasing mouse (mouse up) at some other location (x2, y2) within the image. 

I need to capture these starting and ending coordinates. 

I tried with mouseup and mousedown event but it's not working. When I do the mousedown at destination it does not return anything.

```
var startX, startY;
var endX, endY;
if (!document.all)
    document.captureEvents(Event.MOUSEUP);
document.onmouseup = endPos;

if (!document.all)
    document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = startPos;

function startPos (event)
{
   startX = event.offsetX?(event.offsetX):event.pageX - img1.offsetLeft;
   startY = event.offsetY?(event.offsetY):event.pageY - img1.offsetTop;
}

function endPos (event)
{
   endX = event.offsetX?(event.offsetX):event.pageX - img1.offsetLeft;
   endY = event.offsetY?(event.offsetY):event.pageY - img1.offsetTop;
}

```