Automatically hitting a submit button

This may sound perverse, but:

I have a form with a submit button on it. Every element on the form is input type = hidden. As soon as the page is loaded I want JavaScript to automatically hit the button so the page will submit the details to the web server and deliver the next page.

(It?s a long and boring story why I?m not using a link like meta http-equiv="refresh".)

Thank you for your help and time,

Stoke
StokeAsked:
Who is Participating?
 
CyberSoftCommented:
Hey Stoke,

What browser, version and OS are you using? I've just tested the code in IE5.5, NS4.78 and NS6 on Windows 2000 and it works fine - Netscape 4.78 must have at LEAST one form field between the form tags for it to work though.

Regards,
CyberSoft
0
 
CyberSoftCommented:
Hi Stoke,

In your body tag place the following (assuming your form is called "frmAutoSubmit"):

onload="document.frmAutoSubmit.submit()"

That should automatically submit the form once the page has completed loading in the browser.

Regards,
CyberSoft
0
 
nimaigCommented:
use
<body onLoad="document.forms[0].submit()">
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
StokeAuthor Commented:
Dear Cybersoft and nimaiq,

I know you've right, but I'm getting a script error, "Object doesn't support this property or method" I must be doing something really silly. Here is the body and the form tag:

<body onload="document.frmAutoSubmit.submit()">

<FORM action="www.example.com" NAME="frmAutoSubmit" method=post>
0
 
nimaigCommented:
Try this:

<html>
<head>
</head>
<body onload="document.frmAutoSubmit.submit()">
<FORM action="http://otnxchange.experts-exchange.com/jsp/qShow.jsp?qid=20166375" NAME="frmAutoSubmit" method=post> </FORM>
</body>
</html>
0
 
StokeAuthor Commented:
I'm using Windows ME and IE5.5

I've cut the form down to the minimum - here is the full lot:

<html>
<head>
</head>
<body onload="document.frmAutoSubmit.submit()">
<FORM action="http://www.experts-exchange.com" NAME="frmAutoSubmit" method=post>
<INPUT type="hidden" name="Test" value="test">
<INPUT name="submit" type=submit value="Submit">
</FORM>
</BODY></HTML>

I think I must be doing something really stupid!

Stoke
0
 
Michel PlungjanIT ExpertCommented:
You are.
Do not call the button submit

Michel
0
 
nimaigCommented:
Remove <INPUT name="submit" type=submit value="Submit">
or use different name for the submit button
<INPUT name="submit1" type=submit value="Submit">

This is because the submit button name conflicts with the submit() method of the form.

<html>
<head>
</head>
<body onload="document.frmAutoSubmit.submit()">
<FORM action="http://otnxchange.experts-exchange.com" NAME="frmAutoSubmit" method=post>
<INPUT type="hidden" name="Test" value="test">
<INPUT name="submit1" type=submit value="Submit">
</FORM>
</BODY>
</HTML>
0
 
Michel PlungjanIT ExpertCommented:
change
<INPUT name="submit" type=submit value="Submit">
to
<INPUT name="Submit" type=submit value="Submit">

and document.frmAutoSubmit.submit
is no longer the submit button
0
 
Michel PlungjanIT ExpertCommented:
Beat you by a minute ;-)
0
 
StokeAuthor Commented:
Brilliant work fellas!

Full marks all round. I've awarded this to Cybersoft because he/she was the first one with the answer, but I really want to thank everyone. It's helped me no end.

Thanks very much,

Stoke
0
 
CyberSoftCommented:
Sorry guys went out for a while. Glad you got it working in the end Stoke. Thanks for accepting my solution as the answer.

Regards,
CyberSoft
0
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.

All Courses

From novice to tech pro — start learning today.