Solved

Timer - when 0 will display button to proceed.

Posted on 2007-03-17
3
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 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