Solved

onmouseup is not firing

Posted on 2006-07-18
8
689 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

867 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

21 Experts available now in Live!

Get 1:1 Help Now