Solved

Timer - when 0 will display button to proceed.

Posted on 2007-03-17
3
264 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

815 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

10 Experts available now in Live!

Get 1:1 Help Now