Solved

Automatically hitting a submit button

Posted on 2001-08-10
12
347 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now