Computing.Net > Forums > Programming > Submit Form w/ Javascript

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Submit Form w/ Javascript

Reply to Message Icon

Name: Binary
Date: December 11, 2002 at 15:56:47 Pacific
OS: Win2k
CPU/Ram: AMD 1200/256 DDR
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Binary
Date: December 11, 2002 at 16:02:13 Pacific
Reply:

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


0

Response Number 2
Name: SN
Date: December 11, 2002 at 16:24:34 Pacific
Reply:

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


0

Response Number 3
Name: Binary
Date: December 12, 2002 at 20:28:52 Pacific
Reply:

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


0

Response Number 4
Name: SN
Date: December 12, 2002 at 22:19:42 Pacific
Reply:

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


0

Response Number 5
Name: Binary
Date: December 13, 2002 at 19:43:52 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: Binary
Date: December 13, 2002 at 20:18:53 Pacific
Reply:

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?


0

Response Number 7
Name: SN
Date: December 14, 2002 at 08:34:00 Pacific
Reply:

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


0

Response Number 8
Name: Binary
Date: December 14, 2002 at 23:36:21 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Questions on Macromedia F... New Web Server



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Submit Form w/ Javascript

Diff. b/w javascript and jscript www.computing.net/answers/programming/diff-bw-javascript-and-jscript/14428.html

Creating javascript arrays in forms www.computing.net/answers/programming/creating-javascript-arrays-in-forms/12156.html

PHP Script and HTML Forms www.computing.net/answers/programming/php-script-and-html-forms/7635.html