Generating clientside javascript

Reply

Join Date: Mar 2007
Posts: 22
Reputation: enggars is an unknown quantity at this point 
Solved Threads: 0
enggars enggars is offline Offline
Newbie Poster

Generating clientside javascript

 
0
  #1
Mar 29th, 2007
I'm currently working on my online quiz application. It is based on ASP.
I want to add the countdown timer in every quiz that run.
But the problem is the javascript will go freeze in my ASP, it only run each time i refreshed the page.
Some suggest me to use the clientside javascript to get the time running.
Anybody can help me with this?
Your help is very much to me. Thanks.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 114
Reputation: davidcairns is an unknown quantity at this point 
Solved Threads: 8
davidcairns davidcairns is offline Offline
Junior Poster

Re: Generating clientside javascript

 
0
  #2
Mar 29th, 2007
Try here

http://www.javascript-page.com/timer.html

God I love Google
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 22
Reputation: enggars is an unknown quantity at this point 
Solved Threads: 0
enggars enggars is offline Offline
Newbie Poster

Re: Generating clientside javascript

 
0
  #3
Mar 29th, 2007
Originally Posted by davidcairns View Post
Try here

http://www.javascript-page.com/timer.html

God I love Google
Okay now i can see it.
Well how can set up the limitation time.
I wrote the code :
If document.theTimer.theTime.value = "01:00" {
Stop();
}
But the clock dont even run.
Im new in Java, so any help will be great. Thanks.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 114
Reputation: davidcairns is an unknown quantity at this point 
Solved Threads: 8
davidcairns davidcairns is offline Offline
Junior Poster

Re: Generating clientside javascript

 
0
  #4
Mar 29th, 2007
Make sure you have these options in the html body tag

<body onload="Reset()" onunload="Stop()">

Regards

D
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 22
Reputation: enggars is an unknown quantity at this point 
Solved Threads: 0
enggars enggars is offline Offline
Newbie Poster

Re: Generating clientside javascript

 
0
  #5
Mar 29th, 2007
Originally Posted by davidcairns View Post
Make sure you have these options in the html body tag

<body onload="Reset()" onunload="Stop()">

Regards

D
OKAY here is the code :
I think i miss-place the limitation code.

The limitation code is :
If document.theTimer.theTime.value = "01:00" {
Stop();
}

Where should i place the code?

<script language="JavaScript">

<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com

var timerID = 0;
var tStart = null;

function UpdateTimer() {
if(timerID) {
clearTimeout(timerID);
clockID = 0;
}

if(!tStart)
tStart = new Date();

var tDate = new Date();
var tDiff = tDate.getTime() - tStart.getTime();

tDate.setTime(tDiff);

document.theTimer.theTime.value = ""
+ tDate.getMinutes() + ":"
+ tDate.getSeconds();

timerID = setTimeout("UpdateTimer()", 1000);

If document.theTimer.theTime.value = "01:00" {
Stop();
}


}

function Start() {
tStart = new Date();

document.theTimer.theTime.value = "00:00";

timerID = setTimeout("UpdateTimer()", 1000);
}

function Stop() {
if(timerID) {
clearTimeout(timerID);
timerID = 0;
}

tStart = null;
}

function Reset() {
tStart = null;

document.theTimer.theTime.value = "00:00";
}

//-->

</script>
<body onload="Reset()" onunload="Stop()">
<center><form name="theTimer"><table>
<tr>
<td colspan=3 align=center>
<input type=text name="theTime" size=5>
</td>
</tr>
<tr><td></td></tr>
<tr>
<td>
<input type=button name="start" value="Start" onclick="Start()">
</td>
<td>
<input type=button name="stop" value="Stop" onclick="Stop()">
</td>
<td>
<input type=button name="reset" value="Reset" onclick="Reset()">
</td>
</tr>
</table></form></center>

Oh ya, im working on the resume function so the time will not be reset when the page is being refreshed.
Any helps of this will once again a big thank you from me.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 114
Reputation: davidcairns is an unknown quantity at this point 
Solved Threads: 8
davidcairns davidcairns is offline Offline
Junior Poster

Re: Generating clientside javascript

 
1
  #6
Mar 29th, 2007
It would need to go inside the update function as you say. Also JS timers aren't perfect, so use >= instead of = as follows

If tDate.getMinutes() >= 1 {
Stop();
}


Regards

D
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC