javascript timer countdown

javascript timer countdown

How to disable/enable the javascript timer countdown?

View Answers

September 26, 2011 at 10:46 AM

<!-- CSS Code  -->

#txt {
  border:none;
  font-family:verdana;
  font-size:16pt;
  font-weight:bold;
  border-right-color:#FFFFFF
}



<!-- JavaScript file named: countDown.js  -->

var mins
var secs;

function cd() {
    mins = 1 * m("10"); // change minutes here
    secs = 0 + s(":01"); // change seconds here (always add an additional second to your total)
    redo();
}

function m(obj) {
    for(var i = 0; i < obj.length; i++) {
        if(obj.substring(i, i + 1) == ":")
        break;
    }
    return(obj.substring(0, i));
}

function s(obj) {
    for(var i = 0; i < obj.length; i++) {
        if(obj.substring(i, i + 1) == ":")
        break;
    }
    return(obj.substring(i + 1, obj.length));
}

function dis(mins,secs) {
    var disp;
    if(mins <= 9) {
        disp = " 0";
    } else {
        disp = " ";
    }
    disp += mins + ":";
    if(secs <= 9) {
        disp += "0" + secs;
    } else {
        disp += secs;
    }
    return(disp);
}

function redo() {
    secs--;
    if(secs == -1) {
        secs = 59;
        mins--;
    }
    document.cd.disp.value = dis(mins,secs); // setup additional displays here.
    if((mins == 0) && (secs == 0)) {
        window.alert("Time is up. Press OK to continue."); // change timeout message as required
        // window.location = "yourpage.htm" // redirects to specified page once timer ends and ok button is pressed
    } else {
        cd = setTimeout("redo()",1000);
    }
}

function init() {
  cd();
}
window.onload = init;




<!-- HTML HEAD section -->

<script type="text/javascript" src="countDown.js"></script>



<!-- HTML BODY -->

<form name="cd">
<input id="txt" readonly="true" type="text" value="10:00" border="0" name="disp">
</form>

September 26, 2011 at 10:53 AM

Generally, the timer countdown, is required to stop user of doing something after a certain period of time. The above given example "javascript timer countdown" allows you to start and stop the timer after few seconds. Run the code to see how it function.
Thanks!


September 26, 2011 at 10:57 AM

or you can write the timer enable/disable function as given below..

function timeroff() 
 {
      var b = document.getElementById('Timer1');
      if (!b.disabled) {
            b.disabled = true;
        }
    }
    function timeron() {
        var b = document.getElementById('Timer1');
        if (b.disabled) {
            b.disabled = false;
        }
    }

Remember that the timer countdown function is useful for a program like online examination etc...

Ads









Related Tutorials/Questions & Answers:
javascript timer countdown
a certain period of time. The above given example "javascript timer countdown" allows...javascript timer countdown  How to disable/enable the javascript timer countdown?   <!-- CSS Code --> #txt { border:none; font
Countdown timer to show a link
Countdown timer to show a link  Hi to everyone! I have this code, which is basically a countdown widget...what I want is that when the countdown... whitin a month and a half, and we want this countdown to be in the website
Advertisements
code for timer in java netbeans for online test series countdown timer
code for timer in java netbeans for online test series countdown timer  code for timer in java netbeans for online test series countdown timer
ModuleNotFoundError: No module named 'wg-countdown-timer'
ModuleNotFoundError: No module named 'wg-countdown-timer'  Hi, My... named 'wg-countdown-timer' How to remove the ModuleNotFoundError: No module named 'wg-countdown-timer' error? Thanks   Hi, In your
timer using javascript
timer using javascript  How to display timer on HTML page using JavaScript
JavaScript Clock Timer
JavaScript Clock Timer...; In this section, we are going to show you a clock timer using JavaScript... than 9, then it will add 0 in front of min, sec or hour value like 09 in the timer
ModuleNotFoundError: No module named 'countdown'
ModuleNotFoundError: No module named 'countdown'  Hi, My Python... 'countdown' How to remove the ModuleNotFoundError: No module named 'countdown' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'countdown'
ModuleNotFoundError: No module named 'countdown'  Hi, My Python... 'countdown' How to remove the ModuleNotFoundError: No module named 'countdown' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'countdown'
ModuleNotFoundError: No module named 'countdown'  Hi, My Python... 'countdown' How to remove the ModuleNotFoundError: No module named 'countdown' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'countdown'
ModuleNotFoundError: No module named 'countdown'  Hi, My Python... 'countdown' How to remove the ModuleNotFoundError: No module named 'countdown' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'countdown'
ModuleNotFoundError: No module named 'countdown'  Hi, My Python... 'countdown' How to remove the ModuleNotFoundError: No module named 'countdown' error? Thanks   Hi, In your python environment you
How to design a countdown, design a countdown, countdown
How to design a countdown       It is a great opportunity to learn to draw count down symbol with the help of this example. New File: Insert a new document. Insert
j2me timer and timer task
j2me timer and timer task  have anyone idea to change a direction of bubble, according to changing time.   Please go through the following links: http://www.roseindia.net/j2me/timer-midlet.shtml http
JavaScript
JavaScript  clone JavaScript
ModuleNotFoundError: No module named 'countdown-event'
ModuleNotFoundError: No module named 'countdown-event'  Hi, My... named 'countdown-event' How to remove the ModuleNotFoundError: No module named 'countdown-event' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'countdown-event'
ModuleNotFoundError: No module named 'countdown-event'  Hi, My... named 'countdown-event' How to remove the ModuleNotFoundError: No module named 'countdown-event' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'countdown-event'
ModuleNotFoundError: No module named 'countdown-event'  Hi, My... named 'countdown-event' How to remove the ModuleNotFoundError: No module named 'countdown-event' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'countdown-slackbot'
ModuleNotFoundError: No module named 'countdown-slackbot'  Hi, My... named 'countdown-slackbot' How to remove the ModuleNotFoundError: No module named 'countdown-slackbot' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'countdown-slackbot'
ModuleNotFoundError: No module named 'countdown-slackbot'  Hi, My... named 'countdown-slackbot' How to remove the ModuleNotFoundError: No module named 'countdown-slackbot' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'countdown-event'
ModuleNotFoundError: No module named 'countdown-event'  Hi, My... named 'countdown-event' How to remove the ModuleNotFoundError: No module named 'countdown-event' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'countdown-slackbot'
ModuleNotFoundError: No module named 'countdown-slackbot'  Hi, My... named 'countdown-slackbot' How to remove the ModuleNotFoundError: No module named 'countdown-slackbot' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'easy-countdown'
ModuleNotFoundError: No module named 'easy-countdown'  Hi, My... named 'easy-countdown' How to remove the ModuleNotFoundError: No module named 'easy-countdown' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'fluentcms-countdown'
ModuleNotFoundError: No module named 'fluentcms-countdown'  Hi, My... named 'fluentcms-countdown' How to remove the ModuleNotFoundError: No module named 'fluentcms-countdown' error? Thanks   Hi
javascript
javascript  javascript code to dynamically add table on button click.../javascript/javascriptexamples/javascript-add-row-dynamically.shtml http://www.roseindia.net/javascript/javascript-add-row-to-table.shtml http://www.roseindia.net
Javascript
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
JavaScript
should use JavaScript? Thanks   Hi, JavaScript is scripting language that runs on browser. You have to embed JavaScript in HTML page. Please see JavaScript tutorial. Thanks
JavaScript
JavaScript  how to get full path of a file type in javascript
javascript
javascript  Hi deepak, how to write form validation on javascript
javascript
javascript  write a program to display implement about browsers using javascript
javaScript
javaScript  How to open a browser window that cannot be resized? (HTML + Javascript
javascript
javascript  i have just learned javascript... can you tell me what kind of applications can be made by javascript?? thank you

Ads