<html> <head> <title>Title</title> </head> <body onmousemove="functionSomething('asdfdasfas');"> <script> function functionSomething(x) { //Something alert(x); } var x=event.clientX; var y=event.clientY; alert("asdfdas"); }</script> </body> </html> Code (markup): I've been trying to get this to work but nothing works when you move the mouse, it was in the head originally and I moved it to the body and it still won't work. But if I put alert("something"); in the onMouseMove="" part it works just fine. Anyone see what I'm doing wrong?
Couple of things: - You have a syntax error, } at the end. - You are using event when it is not declared. - Your body is empty. - Misspelled onmouseover method. <html> <head> <title>Title</title> <script> function functionSomething(x) { //Something alert(x); } </script> </head> <body onmouseover="functionSomething('asdfdasfas');"> 126 </body> </html> Code (markup):
<html> <body onmousemove="functionSomething();"> <script> function functionSomething() { document.getElementById('sample').innerHTML = 'X:' + event.clientX + '<br>Y:' + event.clientY; } </script> <div id="sample"></div> </body> </html> HTML: Here you go......