/ Published in: JavaScript

The key to making it work is the event listener that get added using the DOM method that binds it to the mousemove event and declares the event handler. Most event can be bound to a handler this way.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
The HTML: <form name="theform"> x = <input name="xcoord"> y = <input name="ycoord"> </form> <br /><br /> <section> <h3> or as plain text</h3> <span id="spanx"> </span> <span id="spany"> </span> </section> The Javascript: function showit(e) { document.forms.theform.xcoord.value=e.pageX; document.getElementById('spanx').innerHTML='x='+e.pageX; document.getElementById('spany').innerHTML='y='+e.pageY; document.forms.theform.ycoord.value=e.pageY; } if (document.addEventListener) { document.addEventListener("mousemove", function(e){showit(e)}, false) //invoke function }
URL: http://coboldinosaur.com/pages/Capture_Mouse_Position.html
Comments
