Problem using setInterval and clearInterval

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

I am attempting to use the setInterval and clearInterval methods to allow
the user to make an action continuously happen while they hold down the
mouse button on an element. Here are the eventhandlers I am using for the
events:


onmousedown="var decrease=window.setInterval('incdec(-1)',200);"
onmouseup="window.clearInterval(decrease);


The onmousedown eventhandler is starting the Interval perfectly fine, but
the onmouseup does not seem to be doing anything. I could obviously create
an extra button to stop the Interval, but that would defeat the purpose of
being able to make an action repeatedly happen by holding the button down.
Any ideas why the onmouseup does not appear to be working, or does anyone
have any ideas as to another technique to use? Thanks. (NOTE: I have been
doing my testing on Windows XP Professional using Internet Explorer 6.0)
 
Nathan Sokalski said:
I am attempting to use the setInterval and clearInterval methods to
allow the user to make an action continuously happen while they hold
down the mouse button on an element. Here are the eventhandlers I am
using for the events:


onmousedown="var decrease=window.setInterval('incdec(-1)',200);"
onmouseup="window.clearInterval(decrease);

The code in onmousedown handler declares a local variable. Being local,
this variable is only available inside the handler. Inside onmouseup
handler, decrease is undefined. Put an alert in to see for yourself.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
 
Nathan said:
onmousedown="var decrease=window.setInterval('incdec(-1)',200);"
onmousedown="window.decrease=window.setInterval('incdec(-1)',200);"

onmouseup="window.clearInterval(decrease);

onmouseup="window.clearInterval(window.decrease);

Daniel
 
Back
Top