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









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.ADS_TO_REPLACE_1
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
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
Timer and TimerTask
Timer and TimerTask  i have problem of java.lang.IllegalStateException: Task already scheduled or cancelled
Christmas countdown Java
Christmas countdown Java  Assignment: Write a program that reads in a date and calculates the number of days until Christmas for that year . You can assume that the date entered is before December 25 of that year. Dates
Christmas countdown Java
Christmas countdown Java  Assignment: Write a program that reads in a date and calculates the number of days until Christmas for that year . You can assume that the date entered is before December 25 of that year. Dates
Timer - Swing AWT
Timer  How can I make a simple countdown timer in my GUI?  ... { ProgressMonitor progress; static int counter = 0; Timer timer...("Progress bar timer Demo"); setSize(250, 100); setDefaultCloseOperation
Java timer
Java timer  Hi. I want to use a timer in one of my java projects... java.util.Timer; import java.util.TimerTask; public class ToDo { Timer timer;ADS_TO_REPLACE_1 public ToDo ( int seconds ) { timer = new Timer
JavaScript
JavaScript  clone JavaScript
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
ModuleNotFoundError: No module named 'timer'
ModuleNotFoundError: No module named 'timer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'timer' How to remove the ModuleNotFoundError: No module named 'timer'
Difference between Timer and Thread?
Difference between Timer and Thread?  Can anyone tell me about the difference between Timer and Thread, Why we need to have Timer in case we have Thread implimentation startegy in Java
javascript
javascript  how to set the request or session attribute in javascript head part of jsp page
javascript
javascript  Hi sir, This is sinduri, i want to learn javascript, so plz can u help me.how to learn
javascript
javascript  hi sir, if i want to learn javascript. what concepts i want to know
JAVASCRIPT
JAVASCRIPT  I have one textbox and I want to validate that it must start with number(1-0). can anyone tell me a javascript for that ? thanks in advance
Javascript
Javascript   Javascript to check Numeric entry in checkbox.....   Hi Please find the following code for numeric entry validation in javascript function validateBox(){ var data=document.myForm.someText.value
javascript
javascript  hi, I was actually working on to calculate the number of days between two dates of yyyy-mm-dd format using javascript, and when i click on button then number of days should be display in textbox
javaScript
javaScript  . Print a table like below in JAVASCRIPT 5 x 1 = 5 5 x 2 = 10 ΓΆβ?¬Β¦ΓΆβ?¬Β¦ΓΆβ?¬Β¦. 5 x 20 = 100
javascript
javascript  passing javascript values to jsp   Hi Friend, Try the following code:ADS_TO_REPLACE_1 form.jsp: <html> <script>... Javascript value In JSP"> <% String st=request.getParameter("msg"); if(st
Javascript
this format xxx-xxx-xxxx, i want the code in javascript. as a function.   Javascript Phone Number Validation <html> <script> function..." method="post" onsubmit="javascript:return validate();"> Phone Number:<
Javascript
Javascript  Dear Sir, Thank You a lot for your continuos support.Again i am in need of your help. What is the javascript code to disable a link,once... javascript or css Please help me.Urgent Regards Debasis   Hello Friend
Java Timer Task
Java Timer Task  How to assign a task in java at specified date & time (with seconds) using threads
Javascript
Javascript  <html> <head> <script type="text/javascript"> function validateForm() { var sname=document.getElementById('spocname'); var scontact=document.getElementById('spoccontact'); if(sname.value.length

Ads