Quantcast

Monday, March 3, 2008

submit form onload - auto submit - java - ASP - PayPal

Over the years I've tried various ways to get forms to 'autosubmit', or submit when the page is loaded. Some version of '<body onLoad="Javascript:Form.form1.submit()">' may work but I haven't had success with it.

The solution I found today was two simple steps:

1. <body onload='MyForm.MySubmitButtonName.focus()';>
2. <input name="MySubmitButtonName" type="text" value="." onfocus="javascript:submit(MyForm);">

I put step 1 anywhere near the top of the page and step 2 at the end of the form i.e.

<body onload='MyForm.MySubmitButtonName.focus()';>
<form name='MyForm' action='http://www.somewhere.com' method='post'>
<input type="hidden" name="Variable1" value="100">
<input type="hidden" name="Variable2" value="200">
<input name="MySubmitButtonName" type="text" value="" onfocus="javascript:submit(MyForm);">
</form>

Notes: 'MyForm' can be any name but be sure to replace it in all instances. The 'submit' button isn't really a 'submit' button, any input type will do.

I'm using this with ASP pages to submit to PayPal. I want to do some stuff like send an admin e-mail and post to a database before actually turning things over to PayPal without asking the user to click again. With this solution, the user clicks 'pay now' and I can do preliminary tasks and auto route them to PayPal.

Comments

1. Chris said...

My blank page with the form details on it stays within the browser when the PayPal page appears. How can I get the page to close after the submission is made?

2. Chris said...

Also it seems to make PayPal appear as a popup which is blocked as default, however if I use a manual submit is not detected as a popup but just a standard POST.

-- Add Your Comment --

Name
URL
Email
Email address is not published
Remember Me
Comments

CAPTCHA
Write the characters in the image above

Things to Do
John's business web site
  
Google RSS and Gadget

Visit or Join Blog Catalog
Things to Buy

Nice tool to speed up your PC

Look for Pocket Controller Pro
Things to Read
Mezzanine View
Politics - Environment - Technology
Bridging the Gap...
to better writing
Autorotate's Flying Circus
Politics with humor - enjoy
Things to Buy

Best for Windows on Mac

Great backup software - low price
'Who sent you' top 10
Shameless Plugs
VBS Reachout Adventures
Vacation Bible School Program
Keep'n' Safe
Good deals on gun safes
Screw Outfitters
Complete line of Faspac fasteners
Tom Haseltine Photography
Note cards and more
East Point Seafood
Order canned seafood from cannery