469,279 Members | 2,216 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,279 developers. It's quick & easy.

Mouse position error

Hi guys,
I want to use a Curser position function with javascript like this:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Untitled Document</title>
  5. <script language="javascript">
  6. function test(){
  7.     var posx = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  8.     var posy = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  9.     alert(posx+","+posy);
  10. }
  11.       </script>
  12. </head>
  13.  
  14. <body>
  15. <input name="test" type="button" value="click me" onClick="test();"/>
  16. </body>
  17. </html>
  18.  
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:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Untitled Document</title>
  5.  
  6. <script src="js/prototype.js" type="text/javascript"></script>
  7.  
  8. <script language="javascript">
  9. function test(){
  10.     var posx = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  11.     var posy = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  12.     alert(posx+","+posy);
  13. }
  14.       </script>
  15. </head>
  16.  
  17. <body>
  18. <input name="test" type="button" value="click me" onClick="test();"/>
  19. </body>
  20. </html>
  21.  
(I'm using Prototype 1.5.0 btw)
Can anyone help me? I really need the Javascript Framework and the mousepos function working.
Jan 23 '09 #1
3 1592
Dormilich
8,651 Expert Mod 8TB
does the error console (firefox) show any errors? (alternately, you could provide a link, so that we can see for ourselves)
Jan 23 '09 #2
@Dormilich
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
Jan 24 '09 #3
Problem fixed :)
'Event' was supposed to be 'event'.
Jan 24 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by punkin | last post: by
6 posts views Thread by lauren quantrell | last post: by
3 posts views Thread by Emjay | last post: by
13 posts views Thread by Lars Netzel | last post: by
2 posts views Thread by romain.larmet | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.