Live Chat Icon For mobile
Live Chat Icon

How can you get the X Co-ordinates Y Co-ordinates values during the Mouse Movement?

Platform: ASP.NET| Category: Client Side Scripting

The X and y co-ordinates during the mouse movement can be obtained by the following codings.

		<form name='Show'>
			<b>X Co-Ordinate Value:</b><input type="text" name="X" value="0" size="4"> <br>
<b>Y Co-Ordinate Value:</b><input type="text" name="Y" value="0" size="4"> <br> </form> <script language='Javascript'> <!-- // Detect if the browser is IE or not. // If the browser is not IE, we assume that the browser is NS. var IE = document.all?true:false // If NetScape then set up for mouse capture if (!IE) document.captureEvents(Event.MOUSEMOVE) // Set-up to use getMouseXY function onMouseMove document.onmousemove = getMouseXY; // Temporary variables to hold mouse x-y pos.s var tempX = 0 var tempY = 0 // Main function to retrieve mouse x-y pos.s function getMouseXY(e) { if (IE) { // grab the x-y pos.s if browser is IE tempX = event.clientX + document.body.scrollLeft; tempY = event.clientY + document.body.scrollTop; } else { // grab the x-y pos.s if browser is NS tempX = e.pageX; tempY = e.pageY; } // catch possible negative values in NS4 if (tempX < 0){tempX = 0} if (tempY < 0){tempY = 0} // show the position values in the form named Show // in the text fields named MouseX and MouseY document.Show.X.value = tempX; document.Show.Y.value = tempY; return true; } //--> </script> </body> </html>

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.