Solved

Automatically hitting a submit button

Posted on 2001-08-10
12
364 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:Stoke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +1
12 Comments
 
LVL 3

Expert Comment

by:CyberSoft
ID: 6371948
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
 
LVL 9

Expert Comment

by:nimaig
ID: 6371965
use
<body onLoad="document.forms[0].submit()">
0
 

Author Comment

by:Stoke
ID: 6371998
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:nimaig
ID: 6372039
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
 
LVL 3

Accepted Solution

by:
CyberSoft earned 50 total points
ID: 6372066
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
 

Author Comment

by:Stoke
ID: 6372194
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6372216
You are.
Do not call the button submit

Michel
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6372219
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6372222
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6372224
Beat you by a minute ;-)
0
 

Author Comment

by:Stoke
ID: 6372287
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
 
LVL 3

Expert Comment

by:CyberSoft
ID: 6372355
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
alert on input text 2 24
HTML auto refresh to another site 4 28
How to pass values to HTML-5 attribute dynamically? 24 45
Table header must be on top 2 27
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question