By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,718 Members | 1,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,718 IT Pros & Developers. It's quick & easy.

Mouse position error

P: 3
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
Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
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

P: 3
@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

P: 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.