Envoking mouse capturing function onmousedown?

Posted by Babiker on Stack Overflow See other posts from Stack Overflow or by Babiker
Published on 2010-06-02T02:55:51Z Indexed on 2010/06/02 3:03 UTC
Read the original article Hit count: 329

Filed under:
|

I have the following:

<html>
    <script type="text/javascript">
        document.onmousemove = getCursorXY;

        function getCursorXY(e) {
            document.getElementById('cursorX').value = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
            document.getElementById('cursorY').value = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
        }
    </script>

    <body>
        <input id="cursorX" size="3">
        <input id="cursorY" size="3">
        <input type="button" id="button">
    </body>
</html>

With this my mouse coordinates are displayed in the input fields when the page loads and whenever i move the mouse. How can i make this work only when i mousedown over #button and then stop at the last coordinates when i mouseup only over #button?

using firefox 3.6.3

Thanks in advance :)

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about firefox