Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am having some trouble submitting a form with javascript. This is what I am doing:
the problem is it is not waiting 5 seconds before it submits. It seems to just submit as soon as the page loads. Any suggestions?
Thanks

I am having some trouble submitting a form with javascript. This is what I am doing:
[BODY onLoad=setInterval(document.forms.formname.submit(),5000);]
The problem is it is not waiting 5 seconds before it submits. It seems to just submit as soon as the page loads. Any suggestions?
I have tried it with and with a semicolon at the end and the formname field complies with the name i gave my form.Thanks

I could be wrong, but I am pretty sure you are using the setInterval method, which will perform the action at 0, interval, 2*interval, etc. when you should be using the setTimeout method. setInterval will perform it the first time as soon as it loads, whereas setTimeout will wait until interval has passed. Hope this helps,
SN
P.S. You can see an example at http://www.the-cool-place.co.uk/javascript/cutandpaste/cutandpaste5.html

I have tried both methods and they both yield the same results. II am getting a syntax error. What am I doing wrong?

This code worked:
[HTML]
[HEAD]
[/HEAD]
[BODY onload=setTimeout("alert(\"hello\")",5000)]
Testing
[/BODY]
[/HTML]But this code didn't: (got one alert, then an invalid argument error)
[HTML]
[HEAD]
[/HEAD]
[BODY onload=setTimeout(alert("hello"),5000)]
Testing
[/BODY]
[/HTML]I suspect you need quotation marks around your document.forms.formname.submit(). setInterval did, as it turns out, work equally well for me, but I still think setTimeout is a more appropriate function. Let me know if this works.
-SN

I tried both of those examples and only the bottom one popped up a message, but it didn't wait for 5 seconds. I am running win2k, is there a problem with javascript and win2k.

Ok I got it to work. As far as I can tell I cannot put the document.forms.formname.submit() directly in the Body onLoad tag. I put it in a function and after some tinkering I got it to work. Here is what I have. The setTimeout() and setInterval seem to do the same thing.
[HTML]
[HEAD]
[SCRIPT LANGUAGE=javascript]function wait(){
string="document.forms.me.submit();";
setInterval(string,3000);
}[/SCRIPT]
[/HEAD]
[BODY onload=wait()>
Testing
[FORM NAME=me METHOD=post]
[INPUT TYPE=text NAME=me_too]
[/FORM]
[/BODY]
[/HTML]
Thanks for the help guys. Any questions or comments?

Weird that the top example didn't work for you. I was testing in IE 6.0 - you? Sorry I wasn't much help, but I'm glad you got it working.
-SN

I am using IE 5. Maybe that was the problem. I really appriciate your help. I basically took the code off the page you suggested and stripped it down. I couldn't have done it without you.
Thanks
Binary

![]() |
Questions on Macromedia F...
|
New Web Server
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |