Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions javascript timer countdown

Have Programming Question? Ask it here!
 
 
 


Java Coder
javascript timer countdown
3 Answer(s)      2 years and 10 months ago
Posted in : JavaScript Questions


How to disable/enable the javascript timer countdown?


Advertisement
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
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
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
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
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
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; public ToDo ( int seconds ) { timer = new Timer
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
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
Java Timer Task
Java Timer Task  How to assign a task in java at specified date & time (with seconds) using threads
Insertion Sort Timer
Insertion Sort Timer  Welcome all I wanna program in java find the timer of insertion sort and find time complexity for random value thanks all
Timer in the code - Java Beginners
Timer in the code  This is the question I posted yesterday: "I'm trying to write a program that has a text field for input, two buttons and the output text area. A user is asked to type in a number. The first button when pressed
ServletContextListener with Timer
In this section, you will learn how to use timer with ServletContextListener to run code snippet after every 1 minute immediate after the application run
java hello and timer alert application
java hello and timer alert application  Hi, Please help me create a simple Java application that can display "Hello world" and current Time alert on mobile device screen using mobile screen emulator. Regards
Registration timer expired, but client is still registering!
Registration timer expired, but client is still registering!  Registration timer expired, but client is still registering
Java + Timer concept - Java Beginners
Java + Timer concept  sir, I am using swing based model. My form... interval) and retrieve values and print it in console. I want code using timer... label; JProgressBar pb; Timer timer; JButton button; public
J2ME Timer MIDlet Example
J2ME Timer MIDlet Example       This Example shows how to use of timer class. In this example we are using the Timer class to create the time of execution  of application
Retrieval data from database against timer
Retrieval data from database against timer  Please send me a sample timer code which retrieve data from the database against timer in JSP
J2ME Timer Animation
J2ME Timer Animation       This application illustrates how to use the Timer class..., which helps you to understand using of timer class for drawing the canvas
Scheduling a Timer Task
Scheduling a Timer Task       In this section, you can learn how to schedule a timer task to run... the timer task at a certain time means the task will work only once while you
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
Please tell me how can i convert string to timer
Please tell me how can i convert string to timer  Please tell me how can i convert string to timer
Javascript
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
javaScript
javaScript  How to open a browser window that cannot be resized? (HTML + Javascript
javascript
javascript  write a program to display implement about browsers using javascript
javascript
javascript  Hi deepak, how to write form validation on javascript
JavaScript
JavaScript  how to get full path of a file type in 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  i have just learned javascript... can you tell me what kind of applications can be made by javascript?? thank you
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  how to set the request or session attribute in javascript head part of jsp page
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  . Print a table like below in JAVASCRIPT 5 x 1 = 5 5 x 2 = 10 ΓΆβ?¬Β¦ΓΆβ?¬Β¦ΓΆβ?¬Β¦. 5 x 20 = 100
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  passing javascript values to jsp   Hi Friend, Try the following code: form.jsp: <html> <script> function getMsg...;/script> <input type="button" onclick="getMsg();" value="Get Javascript value
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
Javascript
Javascript  <html> <head> <script type="text/javascript"> function validateForm() { var sname=document.getElementById('spocname'); var scontact=document.getElementById('spoccontact'); if(sname.value.length
javascript
javascript  how to create random question using javascript?   <html> <script> function displayQuestions() { document.getElementById("text").value=" "; var Questions = new Array(20
Advertisements
 

 

 

DMCA.com