Solved

onmouseup is not firing

Posted on 2006-07-18
8
686 Views
Last Modified: 2006-11-18
hi,

Can anyone tell me why the onmouseup is not firing when I dpress the mouse button, drag it, it will not fire the onmouseup event. here is my code

    window.onload=function()
    {
                //Apply all the events
           document.onmousemove = function(e){MouseCo(e);}
        for(i=0;i<document.getElementsByTagName('DIV').length;i++)
        {
             document.getElementsByTagName('Div')[i].onmousedown = function(e){MoveElement(e);}
             document.getElementsByTagName('Div')[i].onmouseup = function(){alert("hello");}

        }
    }
   
    function MoveElement(e)
    {
       e = e || window.event;
          DT = e.target || e.srcElement;
    }
0
Comment
Question by:REA_ANDREW
  • 4
  • 4
8 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 17129826
Check this:

    window.onload=function(){
              //Apply all the events
        document.onmousemove = function(e){MouseCo(e);}
        var div = document.getElementsByTagName('DIV');
        for(i=0;i<div.length;i++) {
            div[i].onmousedown = MoveElement;
            div[i].onmouseup = function(){alert("hello");}
            div[i].onmouseout = function(){this.onmouseup()};
        }
    }
 
    function MoveElement(){
         DT = this;
    }  


0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 17129871
Zvonko, thank you for this. I have amended, and it fires on every mouseout

    window.onload=function(){
              //Apply all the events
        document.onmousemove = function(e){MouseCo(e);}
        var div = document.getElementsByTagName('DIV');
        for(i=0;i<div.length;i++) {
            div[i].onmousedown = MoveElement;
            div[i].onmouseup = MouseUp;
            //div[i].onmouseout = function(){this.onmouseup()};
        }
    }
 
    function MoveElement(){
         DT = this;
    }
    function MouseUp()
    {
          alert(this.id);
    }
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 17129879
how can I stop this? I will be dragging the element, so effectively it will not be a mouseout until they mouseup is fired so should that sort it any way?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17129921
Handle the onMouseUp in the document scope.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 20

Author Comment

by:REA_ANDREW
ID: 17129944
Zvonko thanks thats great, I am posting a second question now on dragging.

Cheers again

Andrew
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17129962
Oh, you are welcome.
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 17133864
It seams we forgotten this one.
Here the changed script:


    window.onload=function(){
              //Apply all the events
        document.onmousemove = function(e){MouseCo(e);}
        document.onmouseup = MouseUp;
        var div = document.getElementsByTagName('DIV');
        for(i=0;i<div.length;i++) {
            div[i].onmousedown = MoveElement;
         }
    }

0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 17137430
Sorry I gorgot to accept. Cheers again
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now