Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Timer - when 0 will display button to proceed.

Posted on 2007-03-17
3
Medium Priority
?
270 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 2000 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

Technology Partners: 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!

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to count occurrences of each item in an array.

671 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