?
Solved

set timer between multiple pages

Posted on 2014-08-31
11
Medium Priority
?
274 Views
Last Modified: 2014-09-20
Hi

I need to set a timer in a way that 20 seconds later from an event (page load) It will be redirected to a new page.
The problem is that the user maybe on the page on which I've set the timer - but most probably not.
So I need to know how to set the timer, how to pass it on (if needed),
and how to check in another page if the time runs-out.


Thanks.
0
Comment
Question by:arielbf
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 40295367
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40295700
how to set the timer, how to pass it on (if needed),
What do you mean by "pass it on?"
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40295705
Here's a teaching example showing a countdown timer.  
http://iconoun.com/demo/countdown_timer.php

<?php // demo/countdown_timer.php
error_reporting(E_ALL);

// SET THE TIMER VALUE IN THE PHP SCRIPT
date_default_timezone_set('America/Chicago');
$present = time();
$future  = strtotime('NOW + 7 SECONDS');
$timer   = $future - $present;
?>

<script type="text/javascript">
var interval = "";
var sekonds  = <?php echo $timer; ?>;

function startInterval()
{
    interval = window.setInterval("tTimer()",1000);
}

function stopInterval()
{
    window.clearInterval(interval);
    interval="";
}

function tTimer()
{
    document.thinkTime.tDisplay.value = sekonds--;
    if (sekonds == -1)
    {
        stopInterval();
    }
}
</script>

<script>
document.write('<meta http-equiv=\"Refresh\" content=\"<?php echo $timer; ?>;url=http://lmgtfy.com?q=JavaScript+Timer\">');
</script>

<form name="thinkTime">
This page will automatically search for a JavaScript Timer in
<input readonly class="timerBox" size="1" type="text" name="tDisplay" value="">
<script>startInterval();</script>
seconds.
</form>
<a href="http://lmgtfy.com?q=JavaScript+Timer">Click here if you don't want to wait.</a>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:arielbf
ID: 40295767
I need that my users to solve some questions. They should have 20 secs in total.
So in question 1 the user starts with 20 seconds, he solve it in 5 seconds.
Now he moves to the next page (question no.2) but now he has only 15 seconds.
He solves question no.2 in 7 seconds. Now he moves to the next page (question no.3) but now he has only 8 seconds.
He cannot solve the question in 8 seconds, and the system move him on to some other page.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1000 total points
ID: 40295797
Hmm.. The WWW is not really made for that sort of thing.  Here are the issues.

1. Internet latency - you cannot know the speed of the client's connection or the route that the internet will take to send the messages.  This can vary by more than a second or two at any given moment - enough to trip up an unfortunate site visitor.
2. The nature of JavaScript is such that it is part of the HTML document.  And the WWW runs on a stateless HTTP protocol.  It is unaware of any previous JavaScript.  You might get around this with a cookie, but see #1 above.

In my opinion, this sort of thing is better suited to a single page with several questions, than to several pages with one question each.
0
 

Author Comment

by:arielbf
ID: 40297782
Well, my client needs to present the questions in different pages.

What I did until now
I used asp to see how much time the user has...
and then:

        <img src="whiteSpace.png" border="0" onload="delaySubmit()">      
       
        .... question

      
      <script language='JavaScript'>
      function delaySubmit()
      {
       setTimeout ( "submitPage()", <%=remainder*1000%> );
      }

      function submitPage()
      {
       window.location = "finalpage.asp?id="+<%=ids%>;
      }
      </script>

       But for some reason the delayed redirect is not working...
0
 
LVL 83

Expert Comment

by:leakim971
ID: 40298065
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40298101
Well, my client needs to present the questions in different pages.
Sometimes a client needs a pink unicorn.  Best of luck with it! ~Ray
0
 
LVL 11

Expert Comment

by:Murfur
ID: 40300583
Ray - I just spat out my coffee. Love it!
0
 

Author Closing Comment

by:arielbf
ID: 40334267
Don't like it but must accept it....
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40334324
Recommend deleting this question. The question contemplates a technically incompetent design. There can be no useful answer.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question