Jump to content

Event only fires once


rogerio
 Share

Recommended Posts

EDIT: Found the problem. Why does this onmousedown event only fire once? thanks...

<html><head><title>Navigation List Example</title><style type="text/css">ul {margin:0;padding:0 0 10px 0;width: 100px;font-family: Arial, Helvetica, sans-serif;font-size: 14px;font-weight: bolder;color: #333333;list-style: none;}ul li {margin-bottom: 2px;padding: 2px;text-align: center;}ul li a {color: #FFFFFF;display: block;background-color: #727272;border: medium solid #333333;text-decoration: none;vertical-align: middle;}ul.submenu {margin-top: 10px;}ul.submenu li a {background-color: #fff;border: 0;color: #666;font-size: 12px;height: 18px;}</style><script type="text/javascript">function moveIt(event, obj){x=event.clientX;y=event.clientY;obj.style.position = "absolute";obj.style.top = 75;obj.style.left = 100;}</script></head><body onmousedown="moveIt(event, document.getElementById('move'))" id="show"><h1>Navigation List Example</h1><ul id="move"><li><a href="index.php?menu=home_m">Home</a></li><li><a href="news.php?menu=news_m">News</a></li><li><a href="info.php?menu=info_m">Info</a></li><li><a href="services.php?menu=services_m">Services</a></li><li><a href="contact_us.php?menu=contact_us_m">Contact Us</a></li><li><a href="legal.php?menu=legal_m">Legal Links</a>  <ul class="submenu">   <li><a href="legal.php?menu=legal_m&page=terms_of_use">Terms of Use</a></li>   <li><a href="legal.php?menu=legal_m&page=privacy_policy">Privacy Policy</a></li>  </ul></li></ul> </body></html>

Edited by rogerio
Link to comment
Share on other sites

You told it to move to position 75, 100. That's the place it's going to go to every time you click. This page is running in quirks mode, if it had a DOCTYPE it wouldn't work properly. You need to add "px" to the position units.

obj.style.left = 75 + "px";

Another problem is the event object: I don't think inline event attributes have an event object (except in Internet Explorer where it is global). You need to attach the event handler with Javascript.

document.body.onmousedown = function(e) {    e = e ? e : window.event;    moveIt(e, document.getElementById("move");}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...