We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


page/form time out? pts for quickness

generous asked
Medium Priority
Last Modified: 2010-08-05

I need to limit the amount of time a users has to submit information from a form on a webpage.  The users should have 5 mins to submit their info and after that script must locate them to another page.  If it is possible, the info already inputted should be transferred through the submit button.  

I don't have a clue how to do this or how hard it is, so i hope the pts are accurate.  If not let me know and i will bump it up.
Watch Question

Using JavaScript you could do the timer-thing like this:
<BODY ... OnLoad="timerId=setTimeout('self.location.href=\'goto.htm\'', 5*60000);">
This will set a timer for 5 minutes. Then the browser will be redirected to goto.htm.

<FORM ... OnSubmit="clearTimeout(timerId)">
When the form is submitted the timer is removed.

I don't really get what you mean with
"If it is possible, the info already inputted should be transferred through the submit button."

Could you please explain that part for me?


Wait a minute!

Do you mean that when the time is up the form should be auto-sent and the user should be forwarded to another page?

If so, here's the new onLoad code:
OnLoad="theForm.submit(); timerId=setTimeout('self.location.href=\'goto.htm\'', 5*60000);"

You must also name the form:
<FORM ... NAME="theForm">



See i have a form with info in it that must be updated by users, except that it is locked to allow only one person in at a time.  Now i don't want one person to take 20 mins filling it out while others wait.  So the code must:  1)time the user out and 2) either relocate them to another page Or retain the info in the form by pressing the submit button.  I was thinking of perl code b/c it will allow for removal (using the system rm cmd) of a locking file (thus allowing other to access the page).  I hope this helps.
I can piece this javascript code together to work with some perl, so if you can't think of something else, the pts are yours.

Most Valuable Expert 2014
Top Expert 2015

Wouldn't it be easier to relocate the waiting users to another page?


I don't know if that would be possible, but i doubt it do to the way the perl is written.  I am going to test the javascript after my late lunch.  If it works the pts are yours.  Thanks for the quick responses.

Will this
OnLoad="theForm.submit(); timerId=setTimeout('self.location.href=\'goto.htm\'',
both submit the info and redirect the user?  If it will then the points are yours.

Ooops. Major bug!
Correct onLoad:
"timerId=setTimeout('theForm.submit();self.location.href=\'goto.htm\';', 5*60000);"

Actually, I am not sure if this will work properly...
Maybe that that the posting will be interrupted by the redirect statement.
If it does, I have a solution (nested timers).


Javascript is a decent way to warn your user that their time is limited, and maybe take them to anothe page, but it's a bad way to do this timeout (it won't work)

The timeout has to be implemented on the server-side:

- When someone locks the page, the time is recorded and a hidden field with a lock code is placed into the form.

- The next time someone tries to lock it, the current time is compared to the locked time. If it's greater than five minutes old then the old user's lock is removed and the new user gets the locked page, otherwise they are told they must wait.

- If the old user submits after 5 minutes and they no longer have the lock (which you can tell from the hidden lock code field), you can tell them that their update was ignored since someone else is updating the page. (If noone else has locked the page in the meantime, there's no reason not to allow the update).

That's the sort of system required, javascript alone can't do it. Tell me if you want an example. Hope this helps!


I would love the code!!!!!
thank you.
Unlock this solution and get a sample of our free trial.
(No credit card required)


Umm, I am going to need some time with this one. I was just creating a tmp, if the file existed then the person got a msg saying to try again. Your code (from the parts that i can understand)  seems to do a lot more and i will try to use it.

I don't understand how this code kicks the user out / sends the info automatically after x secs.  Could you just highlight that code?  Sorry for being so difficult.

It is the long weekend and my girlfriend will kill me if i take the laptop camping, so pls give me a few days (tues night).


ps thanks for the frame ideas too.

Alamo, that's a nice piece.  It amazes me sometimes how few of the questions in this topic have much at all to do with perl :)


The code as is doesn't actually submit the page after the timeout, it just puts "Time Expired, submit now!' on the status line.

As I am interpreting your reason for  wanting to autosubmit, it's because your page locking doesn't work properly, it has holes. (Please forgive me if I am wrong on this, I am reading between the lines here). The above script closes the holes, making the automatic submission unnecessary. The timeout is done entirely on the server, depending on action from the client won't work because there are a million reasons that action may not happen. As it is written, the script tells the user they better submit, but will still accept their update after the timeout *as long as* noone else has yet locked the page. If someone else has locked the page in the interim, then they get a message telling them their update was rejected. If someone tries to update a page they haven't locked (for example if the page was in their cache) their update will be rejected. If the client loads the page and then goes away forever, the page lock will still time out properly.

By the way, creating a file unless it already exists is unreliable as a lock mechanism, though admittedly in your situation I wouldn't expect it to fail often. The way the script does it is reliable, though, by locking an existing file for exclusive access and then writing the page lock information to it.

If you really want to auto-submit after the timeout, change the line
 print "  if (secs == 0) { window.status = 'Time Expired, submit now!'; }\n";
 print "  if (secs == 0) { document.forms[0].submit(); }\n";


Thanks, your answer was great.  I have learned a lot, thanks.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.