code to display a Countdown Timer (dynamic)

Answers were Sorted based on User's Feedback



code to display a Countdown Timer (dynamic)..

Answer / 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

code to display a Countdown Timer (dynamic)..

Answer / nandu

<!-- Paste this code into the CSS section of your HTML
document -->

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



<!-- Paste this code into an external JavaScript file named:
countDown.js -->

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Neill Broderick ::
http://www.bespoke-software-solutions.co.uk/downloads/downjs.php
*/

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;




<!-- Paste this code into the HEAD section of your HTML
document.
You may need to change the path of the file. -->

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



<!-- Paste this code into the BODY section of your HTML
document -->

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

Is This Answer Correct ?    20 Yes 18 No

Post New Answer

More JavaScript Code Interview Questions

code to positioning of window in certain dimensions

0 Answers  


program to show a progress bar

0 Answers   Infosys,


write a function to validate a given date

1 Answers  


write a program segment that will ask the user if he wants to computer the perimeter of the area of the triangle. if the perimeter is wanted, ask the measure of the three sides and compute for the perimeter. if the area is wanted, ask for the measures of the base and height and compute for the area. display the computed value

1 Answers  


program that will accept any name and will be stored in an array

2 Answers  






create Drop-Down Navigation Menus

0 Answers   TCS,


how to create an anonymous function

0 Answers  


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

0 Answers   Nest, TCS,


could you please tell me for what javac, javax,swing,awt.*; are using. what is the meaning and differences. and also there are 4 access modifiers in java. public, private, protected, default. what is the meaning of these 4 access modifiers and difference. public is the access modifier void means return data type disp() means function name what mean by static

1 Answers   Infosys,


code to Hide and Show form controls

0 Answers  


code to sorting an array of objects

0 Answers  


Reading which Non-Character Key was pressed

0 Answers  


Categories
  • PHP Code Interview Questions PHP Code (33)
  • JSP Code Interview Questions JSP Code (6)
  • ASP Code Interview Questions ASP Code (5)
  • CGI Perl Code Interview Questions CGI Perl Code (3)
  • JavaScript Code Interview Questions JavaScript Code (63)
  • VB Script Code Interview Questions VB Script Code (20)
  • Shell Script Code Interview Questions Shell Script Code (31)
  • Python Code Interview Questions Python Code (34)
  • WinRunner Code Interview Questions WinRunner Code (1)
  • HTML DHTML XHTML Code Interview Questions HTML DHTML XHTML Code (13)
  • XML Interview Questions XML (43)
  • Scripts_Markup Code AllOther Interview Questions Scripts_Markup Code AllOther (5)