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.
Posted by John at 10:32:53 AM in Web Development (13) |
--- |
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.
6/20/2012