onMouseMove Event

Discussion in 'JavaScript' started by Pudge1, Oct 12, 2013.

  1. #1
    <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?
     
    Pudge1, Oct 12, 2013 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    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):
     
    ThePHPMaster, Oct 12, 2013 IP
  3. HussainMHB

    HussainMHB Member

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #3
    <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......
     
    HussainMHB, Oct 25, 2013 IP