Answer Posted / 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 View All Answers
Reading which Non-Character Key was pressed
code to images to rollover
code to keep a page Out of the browser history
how to create a Draggable element
How to encode and decode URL strings?
Create a ViewState Property?
How to block double clicks
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: