Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question onmouseup event in NS 6

    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>
    Last edited by markivs; 04-25-2003 at 08:50 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    New Coder
    Join Date
    Aug 2002
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    New Coder
    Join Date
    Aug 2002
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PLEASE !! someone help me on this. It's pretty urgent.

    Mark


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •