Mouse position error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wuggles
    New Member
    • Jan 2009
    • 3

    Mouse position error

    Hi guys,
    I want to use a Curser position function with javascript like this:
    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script language="javascript">
    function test(){
    	var posx = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    	var posy = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    	alert(posx+","+posy);
    }
          </script>
    </head>
    
    <body>
    <input name="test" type="button" value="click me" onClick="test();"/>
    </body>
    </html>
    This isn't the problem, this'll work. But when I include the javascript file Prototype.js it won't work anymore, an error will show.
    The error is 'variable e is not defined'
    this code won't work:
    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    
    <script src="js/prototype.js" type="text/javascript"></script>
    
    <script language="javascript">
    function test(){
    	var posx = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    	var posy = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    	alert(posx+","+posy);
    }
          </script>
    </head>
    
    <body>
    <input name="test" type="button" value="click me" onClick="test();"/>
    </body>
    </html>
    (I'm using Prototype 1.5.0 btw)
    Can anyone help me? I really need the Javascript Framework and the mousepos function working.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    does the error console (firefox) show any errors? (alternately, you could provide a link, so that we can see for ourselves)

    Comment

    • Wuggles
      New Member
      • Jan 2009
      • 3

      #3
      Originally posted by Dormilich
      does the error console (firefox) show any errors? (alternately, you could provide a link, so that we can see for ourselves)
      Yeah the error console says 'e is not defined' same as I.E.

      By the way, this is without prototype:
      Untitled Document
      and this is with the prototype:
      Untitled Document

      Comment

      • Wuggles
        New Member
        • Jan 2009
        • 3

        #4
        Problem fixed :)
        'Event' was supposed to be 'event'.

        Comment

        Working...