/    Sign up×
Community /Pin to ProfileBookmark

Using KeyPress to pause a countdown

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>

to post a comment
Full-stack Developer

2 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JJun 03.2003 — Please try the following


[SIZE=1]

<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>



[/SIZE]
Copy linkTweet thisAlerts:
@MjhLkwdauthorJun 04.2003 — 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.
×

Success!

Help @MjhLkwd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...