?
Solved

setTimeout

Posted on 2003-03-10
29
Medium Priority
?
461 Views
Last Modified: 2012-06-27
Please advise how to redirect a page into another page (i.e. Login Page) if the page is in inactivity for certain minutes.  For example, if a user logged in a report page and walked away from the workstation for reasons, it could be a problem since the report contains patient information.   In this case, I like to redirect to the login page after certain minutes if the page is in inactivity.  It should not redirect/refresh the page when users are entering data.
0
Comment
Question by:DanKang
[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
  • 17
  • 9
  • 3
29 Comments
 

Author Comment

by:DanKang
ID: 8103437
I have a partial code:
setTimeout(checktime(),1000)
cout++
0
 
LVL 28

Expert Comment

by:sybe
ID: 8103781
<script>
function ToLoginPage() {
    document.location='loginpage.htm';
}
</script>

<body onload="setTimeOut('ToLoginPage()',30000);">

the number is in milliseconds, so 30000 = 30 seconds.
</body>
0
 

Author Comment

by:DanKang
ID: 8103811
I like to make a bit clearer what I want.    The time should count when the user is not entering anything (inactivity).  As soon as the user enters data, the time should be reset to the maximum (i.e. 20 minutes) again.  

Daniel
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:vosk
ID: 8103838
Instead setTimeout method try with intervals:
<html>
<head>
<script language="JavaScript">
var a, b;
function A()
{
b = 0;
a = window.setInterval("c()",1000);
}
function c()
{
b++;
document.d.e.value = b;
if (b == "5") {window.location = "www.page.html"};
}
function f()
{
b = 0;
}
</script>
</head>
<body onLoad="A();" onKeyPress="f();" onMouseMove="f();">
<form name="d">
<input type="text" name="e" value="">
</form>
</body>
</html>
I have insert a textfield because you can see how that works (just delete it and the statement at the javascript code). The counter is to 5 seconds, and is updated every time that the user moves the mouse or press a key.
jbosch(vosk)
0
 

Author Comment

by:DanKang
ID: 8103855
I like to make a bit clearer what I want.    The time should count when the user is not entering anything (inactivity).  As soon as the user enters data, the time should be reset to the maximum (i.e. 20 minutes) again.  

Daniel
0
 
LVL 3

Expert Comment

by:vosk
ID: 8103894
To reset the counter to 20' (in my script) you have to set the "if..." statement to 1200
jbosch(vosk)
0
 

Author Comment

by:DanKang
ID: 8103917
I like to make a bit clearer what I want.    The time should count when the user is not entering anything (inactivity).  As soon as the user enters data, the time should be reset to the maximum (i.e. 20 minutes) again.  

Daniel
0
 
LVL 28

Expert Comment

by:sybe
ID: 8103960
<script>
function ToLoginPage() {
   document.location='loginpage.htm';
}

var id = setTimeOut('ToLoginPage()',30000);
window.onKeyPress = clearTimeOut(id):
window.onMouseMove = clearTimeOut(id):
</script>

<body>

the number is in milliseconds, so 30000 = 30 seconds.
</body>
0
 

Author Comment

by:DanKang
ID: 8104011
I like to make a bit clearer what I want.    The time should count when the user is not entering anything (inactivity).  As soon as the user enters data, the time should be reset to the maximum (i.e. 20 minutes) again.  

Daniel
0
 

Author Comment

by:DanKang
ID: 8104020
Thank you for your help.

So, should it be this?

<script language="JavaScript">
var a, b;
function a()
{
     b = 0;
     a = window.setInterval("c()",1200000);  // for 20 minutes
}
function c()
{
     b++;
     document.myform.FName.value = b;
     document.myform.LName.value = b;
     document.myform.SSN.value = b;
     document.myform.ADDR.value = b;
     document.myform.ZIP.value = b;
     document.myform.State.value = b;
     document.myform.PhysicianFName.value = b;
     document.myform.PhysicianLName.value = b;
     etc, etc  // for more textboxes or dropdown boxes

     if (b == "1200000") {window.location = "www.mynewpage.html"};
}
function f()
{
     b = 0;
}
</script>


<body onLoad="a();" onKeyPress="f();" onMouseMove="f();">
0
 

Author Comment

by:DanKang
ID: 8104026
Thank you for your help.

So, should it be this?

<script language="JavaScript">
var a, b;
function a()
{
     b = 0;
     a = window.setInterval("c()",1200000);  // for 20 minutes
}
function c()
{
     b++;
     document.myform.FName.value = b;
     document.myform.LName.value = b;
     document.myform.SSN.value = b;
     document.myform.ADDR.value = b;
     document.myform.ZIP.value = b;
     document.myform.State.value = b;
     document.myform.PhysicianFName.value = b;
     document.myform.PhysicianLName.value = b;
     etc, etc  // for more textboxes or dropdown boxes

     if (b == "1200000") {window.location = "www.mynewpage.html"};
}
function f()
{
     b = 0;
}
</script>


<body onLoad="a();" onKeyPress="f();" onMouseMove="f();">
0
 

Author Comment

by:DanKang
ID: 8104028
Thank you for your help.

So, should it be this?

<script language="JavaScript">
var a, b;
function a()
{
     b = 0;
     a = window.setInterval("c()",1200000);  // for 20 minutes
}
function c()
{
     b++;
     document.myform.FName.value = b;
     document.myform.LName.value = b;
     document.myform.SSN.value = b;
     document.myform.ADDR.value = b;
     document.myform.ZIP.value = b;
     document.myform.State.value = b;
     document.myform.PhysicianFName.value = b;
     document.myform.PhysicianLName.value = b;
     etc, etc  // for more textboxes or dropdown boxes

     if (b == "1200000") {window.location = "www.mynewpage.html"};
}
function f()
{
     b = 0;
}
</script>


<body onLoad="a();" onKeyPress="f();" onMouseMove="f();">
0
 
LVL 28

Expert Comment

by:sybe
ID: 8104048
don't hit "refresh" but use the "reload this page" link at the left top of this page, right under your name (it's a bug here on EE)
0
 

Author Comment

by:DanKang
ID: 8104060
Thank you for your help.

So, should it be this?

<script language="JavaScript">
var a, b;
function a()
{
     b = 0;
     a = window.setInterval("c()",1200000);  // for 20 minutes
}
function c()
{
     b++;
     document.myform.FName.value = b;
     document.myform.LName.value = b;
     document.myform.SSN.value = b;
     document.myform.ADDR.value = b;
     document.myform.ZIP.value = b;
     document.myform.State.value = b;
     document.myform.PhysicianFName.value = b;
     document.myform.PhysicianLName.value = b;
     etc, etc  // for more textboxes or dropdown boxes

     if (b == "1200000") {window.location = "www.mynewpage.html"};
}
function f()
{
     b = 0;
}
</script>


<body onLoad="a();" onKeyPress="f();" onMouseMove="f();">
0
 

Author Comment

by:DanKang
ID: 8104065
Thank you for your help.

So, should it be this?

<script language="JavaScript">
var a, b;
function a()
{
     b = 0;
     a = window.setInterval("c()",1200000);  // for 20 minutes
}
function c()
{
     b++;
     document.myform.FName.value = b;
     document.myform.LName.value = b;
     document.myform.SSN.value = b;
     document.myform.ADDR.value = b;
     document.myform.ZIP.value = b;
     document.myform.State.value = b;
     document.myform.PhysicianFName.value = b;
     document.myform.PhysicianLName.value = b;
     etc, etc  // for more textboxes or dropdown boxes

     if (b == "1200000") {window.location = "www.mynewpage.html"};
}
function f()
{
     b = 0;
}
</script>


<body onLoad="a();" onKeyPress="f();" onMouseMove="f();">
0
 

Author Comment

by:DanKang
ID: 8104097
Oh my!  I hit "Refresh" many times.
I am sorry about that.

Daniel
0
 
LVL 3

Expert Comment

by:vosk
ID: 8104154
No, it isn't that. The counter adds 1 every 1000 milliseconds, so if you want to exit from the page at 20' of inactivity you should set the "if..." statement to 1200, remember:
20 minute * (60 seconds / 1 minute) = 1200 seconds
The last code you posted will add 1 to the b variable each 20', and when b = 1200000 then will exit the page, so you will give to the user 20*1200000 seconds of inactivity (6'6 hours aprox).
If you have 20' to spend then try:
<html>
<head>
<script language="JavaScript">
var a, b;
function A()
{
b = 0;
a = window.setInterval("c()",1000);
}
function c()
{
b++;
if (b == "1200") {window.location = "www.page.html"};
}
function f()
{
b = 0;
}
</script>
</head>
<body onLoad="A();" onKeyPress="f();" onMouseMove="f();">
</body>
</html>
Note that I have removed the form where display the counter (also the statement from the javascript referenced to it), because it was only to see how that code works; isn't necessary to display the counter, but if you want to inform the user you can.
jbosch(vosk)
0
 

Author Comment

by:DanKang
ID: 8104589
Thank you for your great explanations.
Your note reminds that I should put the message (clock) saying i.e. “You have 15 minutes 35 seconds left” if the page is in inactivity.   Once the user is entering data on the page, the message (clock) will display “You have 20 minutes left”, which should be static as “20 minutes” as long as the user is working on the page.

Please advise how to put this enhanced feature.

Daniel
0
 
LVL 3

Expert Comment

by:vosk
ID: 8106059
What about that?
<html>
<head>
<script language="JavaScript">
var a, b;
function A()
{
b = 0;
a = window.setInterval("c()",1000);
}
function c()
{
b++;
if (b == "10") {document.all.yh.style.visibility = "visible"};
if (b == "1200") {window.location = "www.page.html"};
var t = 1200 - b;
document.all.time.innerText = t;
}
function f()
{
b = 0;
document.all.yh.style.visibility = "hidden";
}
</script>
</head>
<body onLoad="A();" onKeyPress="f();" onMouseMove="f();">
<div id="yh" style="visibility:hidden">
You have&nbsp;
<span id="time"></span>
&nbsp;seconds left.
</div>
</body>
</html>
That will wait 10 seconds before show the time remaining. Also will exit at 20' of inactivity. The time remaining is displayed in format of seconds, you just have to implement that code to make it display the time in minutes and seconds (if you want).
Only for MSIE
jbosch
0
 
LVL 3

Expert Comment

by:vosk
ID: 8106284
I think that's the final code:
<html>
<head>
<script language="JavaScript">
var a, b;
function A()
{
b = 0;
m = 19;
s = 60;
a = window.setInterval("c()",1000);
}
function c()
{
b++;
if (b == 1200) {window.location="page.html"};
s--;
if (s == -1) {m--; s = 59};
var sunit = "seconds", munit = "minutes";
if (s == 1) {sunit = "second"};
if (m == 1) {munit = "minute"};
if (s <= 9) {s = "0" + s};
if (m <= 9) {m = "0" + m};
if (b == 10) {document.all.yh.style.visibility = "visible"};
document.all.minute.innerText = m + " " + munit;
document.all.second.innerText = s + " " + sunit;
}
function f()
{
b = 0;
m = 19;
s = 60;
document.all.yh.style.visibility = "hidden";
}
</script>
</head>
<body onLoad="A();" onKeyPress="f();" onMouseMove="f();">
<div id="yh" style="visibility:hidden">
You have&nbsp;
<span id="minute"></span>
&nbsp;and&nbsp;
<span id="second"></span>
&nbsp;left.
</div>
</body>
</html>
That script waits 10 seconds before display the time remaining in minutes and seconds.
jbosch(vosk)
0
 

Author Comment

by:DanKang
ID: 8111633
I really appreciate it.
It works really fine.

Daniel
0
 
LVL 3

Accepted Solution

by:
vosk earned 300 total points
ID: 8113295
Glad to help you.
And, is there any point for me? That's only a question...
jbosch(vosk)
0
 

Author Comment

by:DanKang
ID: 8113692
It is my first time to use this site.   I think I have the maximum 75 points for you.  Am I right?

Daniel
0
 
LVL 3

Expert Comment

by:vosk
ID: 8118447
Thank you for the points. I didn't want to force you with my last post. Althought if I can get some points at the same time that I help... then so much the better.
jbosch(vosk)
0
 

Author Comment

by:DanKang
ID: 8119552
No problem at all.   You surely deserve the points.  I am glad that I joined this site.

Daniel
0
 

Author Comment

by:DanKang
ID: 8128452
Can you please help me on this issue?
 
The issue is that {window.location="InsertReportReady.html"}; does not pass the parameters (values) on the form.

If I use {window.location="InsertReportReady.html"}; then it just redirects
the page without passing the values on the form.  

If I use {document.frmTest.submit()}; then it calls InsertReport.html, not
InsertReportReady.html.

How can I resolve this?    Please advise.

Daniel  
0
 
LVL 3

Expert Comment

by:vosk
ID: 8332127
You must submit the form valus to the CGI file or to the file that checks if the passwords are right, and wait till the file returns the new page.
jbosch(vosk)
0
 

Author Comment

by:DanKang
ID: 8334029
I am using ColdFusion for these pages.  Can you please advise?

Daniel
0
 
LVL 3

Expert Comment

by:vosk
ID: 8335284
My advise is to take a look at the ColdFusion on the Web Development Software. There you'll find better answers than any that I could give you about CF.
Sorry if I cannot help you here.
jbosch(vosk)
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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

752 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