Help - Search - Members - Calendar
Full Version: JavaScript Events
Invision Power Services > Community Forums > Community Web Design and Coding
Luke
I'm writing a javascript class... I have a button that's supposed to increment a value in a text box and I want it to keep incrementing if the button is held down. The problem is while I use a loop to keep it incrementing on the mouse down event, it doenst allow for the mouse up event which causes it to keep going and going.

CODE
...
mButton.onmousedown = function()
{
    this.myButtonDown = true;
    this.onmouseup = function()
    {
        this.myButtonDown = false;
    }                
    while( this.myButtonDown == true )
    {
        var theNum = this.id.substr(0,1);
        cColor[theNum]++;
        var myBox = my_getbyid( theNum + 'Color' );
        myBox.value = cColor[theNum];
        this.myClass.update_preview();
    }
}
...


I'm pretty sure I'm doing something wrong. I'm just not sure what's the right way of doing this, since I'm not that good with JavaScript. Is there a DoEvents thign I can use in my loop? Something else?
Luke
Ok this is getting VERY flustrating. For some reason the onMouseUp event will not fire until the onMouseDown function finishes. I would be able to use setInverval, but that function will not include the same area of the class... As in when I fire the function, "this" inside the function doesnt mean the same thing unless I call it directly....
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.