| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||||||
|
||||||||
|
Below is the code needed to display count down in HTML page
using javascript. You define container for the count down (either <span> or <div> tag) and the initial value, and the code updates the time automaticlly in the format HH:MM:SS You can also control the style of the container using standard CSS, as demonstrated in the below and attached code. To activate the count down in one of your existing pages you have to follow two steps: 1. include the attached CountDown.js file with: Code:
<script type="text/javascript" src="CountDown.js"></script> 2. have such javascript in the <head> section: Code:
<script type="text/javascript">
window.onload=WindowLoad;
function WindowLoad(event) {
ActivateCountDown("CountDownPanel", 100);
}
</script>
where "CountDownPanel" is the ID of the container (i.e. you should have <span> or <div> with this ID) and 100 is the time in seconds to be counted. full source code: javascript Code:
html4strict Code:
edit: I've added AdvancedCountDown.zip file with advanced options:
edit: Added extra functionality in the advanced options:
edit: Added extra functionality in the advanced options:
Happy Programming! ![]() Last edited by Shadow Wizard : November 24th, 2008 at 05:38 AM. Reason: updated advanced countdown files |
|
#2
|
|||
|
|||
|
my onmouseover doesn't work now
Hi Shadow Wizard,
I would like to use your code. It's cool. I have a question, though. I have a complicated multipage classic ASP, VB Script, SQL Server and Javascript web site. When I included your code - which works well! Thank you. - my mouse over stopped working. Here is the code I'm using for the mouseover: Code:
%>
<INPUT TYPE=BUTTON STYLE='font-size:10px;width:140px'
onClick="add_commodity(<% =RS("CommodityID") %>,'<% =Trim(RS("Commodity")) %>')"
VALUE='<% =Trim(RS("Commodity")) %>'
onMouseOver="writetxt('<% =Replace(msgtxt,"'","") %>')"
onMouseOut="writetxt(0)">
<%
I inherited this code and its a real mix of stuff with VB Script writing html. Do you know if there is something natively incompatible with your code (maybe the onload?) and onmouseover? I'm really at a loss as to where to start looking. Thanks, Chris |
|
#3
|
||||
|
||||
|
yes those lines are overwriting the window load:
Code:
window.onload=WindowLoad;
function WindowLoad(event) {
ActivateCountDown("CountDownPanel", 100);
}
if you already have onload code, you have to add this to my function. attach the whole page source code in zip file and I'll have a look - hopefully it will be something simple and quick. |
|
#4
|
|||
|
|||
|
zip file of our source
Hi ShadowWizard,
I am unable to attach all the source files. This web site is huge with multiple includes and intertwined code. In fact, you won't find the </BODY> in this file. It gets included down the stream someplace. I started over inserting your code to make sure I followed your directions precisely and ended up with the attached code. The words: "Time remaining" is displayed on the page, but the countdown numbers do not appear. The onmouseover DOES work with this version of the code. Thanks for your help, Chris |
|
#5
|
||||
|
||||
|
ok, in header.asp change those lines:
Code:
<script type="text/javascript">window.onload=WindowLoad;function WindowLoad(event)
{ ActivateCountDown("CountDownPanel", 100);}</script>
to be this: Code:
<script type="text/javascript">
window.onload=WindowLoad;
function WindowLoad(event) {
loadCookies();
ActivateCountDown("CountDownPanel", 100);
}
</script>
and this: Code:
<body onload="loadCookies();" MARGINHEIGHT="0" MARGINWIDTH="0" LEFTMARGIN="0" TOPMARGIN="0" BOTTOMMARGIN="0" RIGHTMARGIN="0"> to this: (remove the function from the body tag) Code:
<body MARGINHEIGHT="0" MARGINWIDTH="0" LEFTMARGIN="0" TOPMARGIN="0" BOTTOMMARGIN="0" RIGHTMARGIN="0"> |
|
#6
|
|||||||||
|
|||||||||
|
Timer
Hi!!
I found your timer useful for my project. Thanks a lot. i have 1 question. After the message your time has expired i want it to go to a different page. please send me the codings for this to Thanks a lot Quote:
|
|
#7
|
||||
|
||||
|
Quote:
to do this add this line to the code: Code:
if (_currentSeconds <= 0) {
alert("your time has expired!");
document.location = "otherpage.html";
return;
}
add the line in bold to the code in CountDownTick function. |
|
#8
|
|||
|
|||
|
Hello...
I have a quiz application based on ASP. I use paging, which is showing only one question per page. I want to set a time limitation on the application. The problem is i cant use the window.onload since the time will started again if we move to another question. What i want to do is i want the time limitation only loaded once at the beginning. though we move to the prev or next page, the time will keep on counting without being started again. Can you help me with this? Many thanks for the helps.... |
|
#9
|
||||
|
||||
|
for this, ASP or some other server side language is needed.
assuming you work with ASP, assign session variable with the current date and time when the user begin the quiz: Code:
Session("TimeQuizBegin") = Now
now, change this line: Code:
ActivateCountDown("CountDownPanel", 100);
to this: Code:
ActivateCountDown("CountDownPanel", <%=(600-Abs(DateDiff("s", Now, Session("TimeQuizBegin"))))%>);
replace 600 with the amount of seconds the user has to complete the quiz, in the above code it's 10 minutes. good luck and let me know if you bump into any further problem. ![]() |
|
#10
|
|||
|
|||
|
timer gets refreshed on click of back and refresh
hi all...
in my application count down timer is working fine.. but the problem is onclick of back button / refresh button timer will be refreshed that is it starts its count from the starting. actually this shouldnt happen in my application. when the user clicks back button or refresh button, i want to call button click event by which user will be to taken to the next question in the online quiz. but am not getting how to achieve this. so if anybody could help me in this.. tks in advance regards, Shubha |
|
#11
|
||||
|
||||
|
read my previous reply - what you need is to store
the time on the server, client side scripting lack what you need. |
|
#12
|
|||
|
|||
|
Awesome script
Hi,
I just found this script and have added it to my website and it's working great. I have a couple of questions. 1. I have added the script to my master page so it shows on every page which is what I want. The question is how to make it so the countdown does not start over everytime I go to a new page? 2. Is there anyway to loop this so that when the countdown expires and the window pops up and the user clicks ok it will reset and start the countdown again? Thanks in advance for your help Dan |
|
#13
|
||||
|
||||
|
hi Dan,
answer to your first question: read my previous reply in this thread and the one before. this question has been asked already. answer to your second question: change this block of code: Code:
if (_currentSeconds <= 0) {
alert("your time has expired!");
return;
}
to this: Code:
if (_currentSeconds <= 0) {
alert("your time has expired!");
_currentSeconds = 120; //two minutes
}
of course, change the number to whatever amount of seconds you wish. |
|
#14
|
|||
|
|||
|
submit the form after timeout
Hi....
Thanks for ur code.. I was able to run the timer code successfully.... I am a newbie to java script... And i want to know how should i submit(post method) my html form after timeout. Thanks for ur help... |
|
#15
|
||||
|
||||
|
change this line:
Code:
alert("your time has expired!");
to this: Code:
document.forms[0].submit(); I assume you have only one form in your page. you can also have both the alert and the submit. |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Javascript Countdown Timer |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|