code to display a Countdown Timer (dynamic)

Answer Posted / roushan

<html>
<head>

<style type="text/css">
#txt {
border:none;
font-family:verdana;
font-size:16pt;
font-weight:bold;
border-right-color:#FFFFFF
}
</style>
<script>
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;


</script>



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

Is This Answer Correct ?    15 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how to get the User's Time of Day

1677


code to detect versions of different browsers like internet explorer, netscape, mozilla, opera etc

1742


determine which Element received an Event

1909


I have a doubt regarding including tags in a function. I have written a function in javascript in a html page. The function got called by clicking a button, i want to display the results in same html page by placing tags in the function. (this hmtl page is static page) Is this possible? example:


Code to Block submission of form by pressing Enter Key

2089


How to encode and decode URL strings?

1802


code to detect availability of cookies

1789


How to block double clicks

1626


how to Auto Scroll the page

1635


how to pass data between pages using Cookies

1854


program to show a progress bar

2132


how to create Expandable and Collapsible Menus

2660


code to sorting an array of objects

1997


Create a Menu that can be activated while clicking on Right Mouse button

1715