Staredit Network

Staredit Network -> Computers and Technical -> Javascript assistance required.
Report, edit, etc...Posted by Centreri on 2006-10-22 at 22:40:57
I'm hopeless at javascript and while working on my site, I thought that instead of just saying the time left to be logged in when you refresh to a new page, I wanted it to change dynamically and accurately. Therefore, I needed a simple Javascript script that takes a set number of seconds (to be determined by the PHP script), counts down, second by second until 0 and automatically redirects to another page, which I'll edit in. If anyone can write this script I'll appreciate it smile.gif.
Report, edit, etc...Posted by Pie_Sniper on 2006-10-22 at 22:57:00
CODE
function Timer( SECONDS )
{
  if( SECONDS == 0 )
  {
    location.href = "RedirectPage.php";
  }
  document.getElementById( "Timer" ).innerHTML = SECONDS + " seconds";
  setTimeout( "Timer( " + ( SECONDS - 1 ) + " )", 1000 );
}
...
<body onload="Timer( <?php echo $Seconds; ?> );">

Like that?
Report, edit, etc...Posted by Pie_Sniper on 2006-10-23 at 18:07:17
Shouldn't it be <body<?php if (isset($_COOKIE['login'])) {echo(" onload=\"Timer( " . $loginTimeLeft . " );\"");}?>>?
Report, edit, etc...Posted by Centreri on 2006-10-23 at 18:13:12
Here's what I have:

In Mainpage.php. Body tag:
CODE
<body <?php if (isset($_COOKIE['login'])) {echo(" onload=\"Timer( \" . $loginTimeLeft; . \" );\"");}?> >


Echoed further on:
CODE
You are logged in " . $loginTimeLeftGrammarModifier1 .  "<span id=\"timeLeftCountdown\"><b>" . $loginTimeLeft . "</b></span>" . $loginTimeLeftGrammarModifier2 . "</font>


and the function:
CODE
function Timer( SECONDS )
{
 if( SECONDS == 0 )
 {
   location.href = "RedirectPage.php";
 }
 document.getElementById( "timeLeftCountdown" ).innerHTML = SECONDS + " seconds";
 setTimeout( "Timer( " + ( SECONDS - 1 ) + " )", 1000 );
}


It appears the same as it did before, not counting down. There is no secondary counting down meter next to the static one, as could haver happened, just no change.
And yes, the function is embedded.
Report, edit, etc...Posted by Centreri on 2006-10-23 at 18:29:57
Oops. I really should learn these PHP5 tricks, much less room for errors like this. Thanks a lot, works perfectly.
Next Page (1)