Solved

Timer - when 0 will display button to proceed.

Posted on 2007-03-17
3
262 Views
Last Modified: 2010-05-18
I need an asp timer that will count down from 30 minutes onLoad and then at 0 seconds will display a button that will allow them to proceed.  In other words, they cannot proceed to the next page until the 30 minute timer is up, therefore I don't want the Proceed button to appear until the timer hits 0.  This should be a pretty simple proc for someone who knows javascript :)
0
Comment
Question by:dcass
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Louis01 earned 500 total points
ID: 18742765
<script language="JavaScript">

<!--
// This script is loosely based on one created by someone else. He requested:
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com

var totDuration = 1000 * 60 * 30; //1000 milli-seconds * 60 seconds * 30 minutes
var totTimerID = 0;
var timerID = 0;
var tStart  = new Date();

function ActionAfterWait() {
  Stop();
  alert('Expired!');
  //Put the proceed enable here
  //theTimer.cmdProceed.style.disabled = false;
}

function UpdateTimer() {
   clearTimeout(timerID);

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

   tDate.setTime(totDuration - tDiff);
   document.theTimer.theTime.value = tDate.getMinutes() + ":" + tDate.getSeconds();
   
   timerID = setTimeout("UpdateTimer()", 1000);
}

function Start() {
   clearTimeout(timerID);
   clearTimeout(totTimerID);
   timerID  = 0;
   totTimerID = 0;
   document.theTimer.theTime.value = "30:00";
   totTimerID = setTimeout("ActionAfterWait()", totDuration);

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

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

function Stop() {
    clearTimeout(timerID);
    clearTimeout(totTimerID);
    timerID  = 0;
    totTimerID = 0;
    tStart = null;
}

//-->

</script>

<body onload="Start()" onunload="Stop()">
<form name="theTimer">
<table>
   <tr>
      <td colspan=3 align=center>
         <input type=text name="theTime" size=5>
      </td>
   </tr>
   <tr>
</table>
</form>
</body>
0
 

Author Comment

by:dcass
ID: 18744315
The timer works great, but doesn't solve the button appearance problem.
Here is what I added, but it does not work.  It shows the timer, which is great, but never shows the button.  I've tried the timer as all kinds of field types, but can't get it to work.
<% if cstr(theTime) <> "0:0" then %>
        <input type=text name="theTime" size=3 readonly>
<% else %>
       <INPUT TYPE="submit" style="border:1px solid #000000; padding-top:2; padding-bottom:1"  NAME=dest VALUE="Advance" onClick="document.forms[0].action='Advance.asp'" >
<% end if %>

Help with this and it's all done!
0
 

Author Comment

by:dcass
ID: 18744425
Got it!!!function ActionAfterWait() {
  Stop();
  alert('You may proceed to the next segment now!');
// I added this next line
  document.getElementById('Submit').disabled = false;
}

function Start() {
   clearTimeout(timerID);
   clearTimeout(totTimerID);
   timerID  = 0;
   totTimerID = 0;
   document.theTimer.theTime.value = "30:00";
   totTimerID = setTimeout("ActionAfterWait()", totDuration);
   document.theTimer.theTime.value = "30:00";
   timerID  = setTimeout("UpdateTimer()", 1000);
// and I added this line
   document.getElementById('Submit').disabled = 'disabled';
}

and this:
   <input type=text name="theTime" size=3 readonly>
   <INPUT TYPE="submit" id="submit" style="border:1px solid #000000; padding-top:2; padding-bottom:1"  NAME=dest VALUE="Advance" onClick="document.forms[0].action='Advance.asp'" >
                               
and it works exactly the way I want it to.
Thanks!!!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now