Solved

Automatically hitting a submit button

Posted on 2001-08-10
12
373 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

688 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