Click to See Complete Forum and Search --> : Ending a repeating function


PaulC
11-28-2002, 10:33 AM
I have managed to sucessfully code a set of functions that allow, upon a mouse click on an image, a two-digit counter to move up one or down one. The counter itself is displayed as two images.

I am now trying to make the counter continue to add one if the mouse key is held down and while this has been sucessful, the repeating function doesn't stop when the mouse button is released.

The relevant code is given below and any help is appreciated.

Paul

<img name="upArrow" src="upArrow.jpg" border="0" height="27" width="28" onmousedown="Up();">

function Up() {
var upTime, upTens, upUnits, imgLocala, imgLocalb, imgLen, iPosit;
imgLocala = document.images.a.src;
imgLocalb = document.images.b.src;
imgLen = imgLocala.length;
iPosit = imgLen - 5;
for (i=0; i<=9; i++) {
if (imgLocala.charAt(iPosit) == i) upTens = i;
if (imgLocalb.charAt(iPosit) == i) upUnits = i;
}
upTime = upTens + '' + upUnits;
if (upTime < 99) {
if (imgLocalb.charAt(iPosit) == 9) {
document.images.a.src = eval("c"+(Math.floor(upTime/10)+1)+".src");
document.images.b.src = c0.src;
} else {
document.images.b.src = eval("c"+((parseFloat(upTime)%10)+1)+".src");
}
if (document.images.upArrow.onMouseDown) {
return;
} else {
setTimeout("Up()", 1000);
}
}
}