Click to See Complete Forum and Search --> : Using KeyPress to pause a countdown


MjhLkwd
06-02-2003, 06:20 PM
Using KeyPress to pause a countdown.

<HTML>
<Head>
<Script Language="JavaScript">

var tick = 0;
var holdTick = 0;
var thisEvent = "";



function hold(){

window.status = "The Slideshow is Paused...";
if (thisEvent == 'keydown'){setTimeout("hold()",100);
tick = holdTick};

}

function checkHold() {

thisEvent = event.type;
if (thisEvent == 'keydown'){hold();}


}

function writeTick(){
++tick;
window.status= tick;
if (thisEvent != 'keydown'){holdTick = tick-1};

}

function countdown(){
StartBtn.blur();
writeTick();
if (tick == 10){window.status = "Done"}
else{setTimeout("countdown()",1000)}


}



</Script>
</Head>

<Body onKeydown="checkHold()"; onKeyup="checkHold()">

<IMG src="image1.gif">
<BR><BR>
<input type="button" name="StartBtn" value="Start" onClick="countdown()">
</Body>

</HTML>

Mr J
06-03-2003, 03:16 PM
Please try the following



<HTML>
<Head>
<Script Language="JavaScript">

var tick = 0;

function countdown(){
document.f1.StartBtn.disabled=true
tick++
window.status= tick;
showcount.innerText=tick
if (tick == 10){window.status = "Done"}
else{
timer=setTimeout("countdown()",1000)}
}


function checkHold(){
clearTimeout(timer)
window.status = "The Slideshow is Paused...";
}
document.onkeypress = checkHold
document.onkeyup = countdown

</Script>
</Head>

<Body>

<div id="showcount"></div>
<BR><BR>
<form name="f1">
<input type="button" name="StartBtn" value="Start" onClick="countdown()">
</form>
</Body>

</HTML>

MjhLkwd
06-04-2003, 03:48 PM
Yes, I see. Thank you for posting this. You know, I never knew that JS could simply "stand alone" in the Header. I thought it always had to be within a function, except for global variables. I haven't added this pause feature to my Slideshow code yet, there are other concerns, but I'm confident that between your post and what I was able to accomplish, I will able to do so.