Welcome to Dream.In.Code
Become an Expert!

Join 149,517 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,372 people online right now. Registration is fast and FREE... Join Now!




Form timeout auto submit

 
Reply to this topicStart new topic

Form timeout auto submit, after time out the form will auto submit

jilong
21 May, 2007 - 10:56 PM
Post #1

New D.I.C Head
*

Joined: 17 May, 2007
Posts: 32


My Contributions
I would like to set the time limit for my html survey form, after the time limit the script will auto submit and redirect to the thanks page.

Below is the code i used. but it come out the error message "object does't not support the propperty or method."

can someone please help me on this, thanks

CODE

<script language="Javascript">
<!--
var countdown = "900"

function doCount() {
    if (countdown > 0) {
        countdown--
    }
    else {
    setTimeout('document.authenticate.submit()')
                document.location = "http://www.mypage.com/thank.html"
    }

window.status=countdown + " seconds left to complete the questionnaire."
setTimeout('doCount()',1000)
}

doCount()
//-->
</script>


CODE

<form name="authenticate">
..
..
..
    <input type="submit" value="Submit" name="submit">
    <input type="reset" value="Reset" name="reset">
</form>


This post has been edited by jilong: 22 May, 2007 - 12:08 AM
User is offlineProfile CardPM
+Quote Post

Oaty
RE: Form Timeout Auto Submit
22 May, 2007 - 05:23 AM
Post #2

New D.I.C Head
*

Joined: 10 May, 2007
Posts: 28


My Contributions

I ran into this myself a while ago. If I remember right, you can't call submit on a form from Javascript, or because you have a button named "submit" the scripts confused. I believe that's your property error. A way around this is to call the click() method on your submit button:
CODE
setTimeout('document.authenticate.submit.click()')


That will act as if a user clicked the submit button.

On another note, your redirect will never happen! Once you submit a form, the browser is "redirected" to the page listed in your "action" property. The redirect should be the last thing done on the page/script that your action calls.
User is offlineProfile CardPM
+Quote Post

ahmad_511
RE: Form Timeout Auto Submit
22 May, 2007 - 08:20 PM
Post #3

D.I.C Regular
Group Icon

Joined: 28 Apr, 2007
Posts: 351



Thanked: 8 times
Dream Kudos: 400
My Contributions
Hi.
Try this code it's simple
CODE

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script language="javascript">
countdown=900
function docount(){
if (countdown>0){
countdown--;
window.status=countdown + " seconds left to complete the questionnaire."
timer=setTimeout("docount()",1000)}
else{
clearTimeout(timer)
authenticate.submit()
document.location.href="../../All Users/Documents/My Pictures/Sample Pictures/Winter.jpg"
}
}
</script>
</head>

<body onload="docount()">
<form name="authenticate" method="POST" action="../../All Users/Documents/My Pictures/Sample Pictures/Blue hills.jpg">

    <input type="submit" value="Submit" name="any_thing_but_submit">
    <input type="reset" value="Reset" name="reset">
    <input type="text" name="T1" size="20"></form>
</body>
</html>

By the way don't ever set the name of any element within a form to "submit" when you need to use javascript to submit that form and that what you forgot about
User is offlineProfile CardPM
+Quote Post

jilong
RE: Form Timeout Auto Submit
22 May, 2007 - 10:27 PM
Post #4

New D.I.C Head
*

Joined: 17 May, 2007
Posts: 32


My Contributions
QUOTE(Oaty @ 22 May, 2007 - 06:23 AM) *


CODE
setTimeout('document.authenticate.submit.click()')


That will act as if a user clicked the submit button.



Thanks Oaty it work. after i add the thank page to action the redirect work also biggrin.gif

QUOTE(ahmad_511 @ 22 May, 2007 - 09:20 PM) *

Hi.
Try this code it's simple
By the way don't ever set the name of any element within a form to "submit" when you need to use javascript to submit that form and that what you forgot about


Hi ahmad i had try this code also, but it show me "object doesn't support for this property or method" for this line

CODE
clearTimeout(timer)


is be IE7 problem or i mess out something?
User is offlineProfile CardPM
+Quote Post

ahmad_511
RE: Form Timeout Auto Submit
23 May, 2007 - 01:55 PM
Post #5

D.I.C Regular
Group Icon

Joined: 28 Apr, 2007
Posts: 351



Thanked: 8 times
Dream Kudos: 400
My Contributions
Hello..
I don't know what to say, But I have IE7 and there is no error occurres when running the script!...
But please double check if you still have a "submit" button with "submit" name;if you do try to rename it to any thing else.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:10PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month