zenon905 Posted March 25, 2008 Share Posted March 25, 2008 var intfunction gen(){ var int=setInterval('lot()', 1)}function lot(){ var ran=Math.floor(Math.random()*11) document.getElementById("box").value=ran}function num(){ clearInterval(int)}<input type=button id='a' value="Start The Numbers" onclick=gen()><p><input type=button id='b' value="Take Your Chance!" onclick=num()><p> When I click button b, it doesn't stop the interval and it still continues to work. I tried int=window.clearInterval(int) and var int=self.setInterval like from the clock example, but it still doesn't work. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 25, 2008 Share Posted March 25, 2008 Remove the "var" keyword from the gen function. Using var makes the variable local to the function. If you want to use the global version of the variable then leave off var. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.