Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q917 How can I count down from 15 seconds and then display an alert message?

You are here: irt.org | FAQ | JavaScript | Date | Q917 [ previous next ]

Try:

<form name="timer">
<input type="text" value="" name="field">
</form>

<script language="JavaScript"><!--
var counter = 15;

function countDown() {
    document.timer.field.value = counter-- + ' seconds left';
    if (counter != -1)
        setTimeout('countDown()',1000);
    else
        alert('You lose');
}

countDown();
//--></script>

©2018 Martin Webb