setTimeout

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.
DanKangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DanKangAuthor Commented:
I have a partial code:
setTimeout(checktime(),1000)
cout++
0
sybeCommented:
<script>
function ToLoginPage() {
    document.location='loginpage.htm';
}
</script>

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

the number is in milliseconds, so 30000 = 30 seconds.
</body>
0
DanKangAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

voskCommented:
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
DanKangAuthor Commented:
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
voskCommented:
To reset the counter to 20' (in my script) you have to set the "if..." statement to 1200
jbosch(vosk)
0
DanKangAuthor Commented:
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
sybeCommented:
<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
DanKangAuthor Commented:
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
DanKangAuthor Commented:
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
DanKangAuthor Commented:
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
DanKangAuthor Commented:
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
sybeCommented:
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
DanKangAuthor Commented:
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
DanKangAuthor Commented:
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
DanKangAuthor Commented:
Oh my!  I hit "Refresh" many times.
I am sorry about that.

Daniel
0
voskCommented:
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
DanKangAuthor Commented:
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
voskCommented:
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
voskCommented:
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
DanKangAuthor Commented:
I really appreciate it.
It works really fine.

Daniel
0
voskCommented:
Glad to help you.
And, is there any point for me? That's only a question...
jbosch(vosk)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DanKangAuthor Commented:
It is my first time to use this site.   I think I have the maximum 75 points for you.  Am I right?

Daniel
0
voskCommented:
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
DanKangAuthor Commented:
No problem at all.   You surely deserve the points.  I am glad that I joined this site.

Daniel
0
DanKangAuthor Commented:
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
voskCommented:
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
DanKangAuthor Commented:
I am using ColdFusion for these pages.  Can you please advise?

Daniel
0
voskCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.