Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Script Timer

Status
Not open for further replies.

danarashad

Programmer
Nov 2, 2006
115
US
I have a timer on my page but it doesn't show when someone uses safari, I have posted code. Thanks in advance.

<script language="JavaScript">
<!--
var thisTime = <cfoutput>#userTimeOut#</cfoutput>;
var timerID = null;
var timerRunning = false;
var startDate;
var startSecs;
var SessionKill = thisTime*60;

function startclock()
{
startDate = new Date()
startSecs = (startDate.getHours()*60*60) + (startDate.getMinutes()*60)+ startDate.getSeconds()
showtime()
}

function showtime()
{
// this doesn't work correctly at midnight...
var now = new Date();
var nowSecs = (now.getHours()*60*60) + (now.getMinutes()*60) + now.getSeconds();
var elapsedSecs = SessionKill - (nowSecs - startSecs);

if(elapsedSecs == 299){
alert("Session will time Timed Out in 5 minutes.\n\n Any Data Not Saved will be lost!");
}
if(elapsedSecs < 1){
var path = "<CFOUTPUT>#webpath#/ComCenter/</CFOUTPUT>";

var URL = 'logout.cfm';
var thisTime = 0;
window.location.href = URL;

alert("Session Has Timed Out\n\n Any Data Not Saved will be lost!");
}
else {
var minutes = Math.floor( elapsedSecs / 60 );
elapsedSecs = elapsedSecs - (minutes*60);
var seconds = elapsedSecs;
var timeValue = "";
timeValue += ((minutes < 10) ? "0" : "") + minutes;
timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
document.all('timer').value = timeValue;
timerID = setTimeout("showtime()",1000);
}
}
//--></script>
the display is here
<input name="timer" size="4" readonly="true">
 
Make life easier for yourself... give the input an ID:
Code:
<input name="timer" [!]id="[COLOR=blue]timer[/color]"[/!] size="4" readonly="true">
And then change the point at which you update the input to something like this:
Code:
[s]document.all('timer').value = timeValue;[/s]
[!]document.getElementById('[COLOR=blue]timer[/color]').value = timeValue;[/!]

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top