SitePoint Sponsor |
|
User Tag List
Results 1 to 11 of 11
Thread: Automatic form submission error
-
Jul 7, 2008, 08:29 #1
- Join Date
- Feb 2008
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Automatic form submission error
Hi,
I am writing a very simple script to automatically submit a form when the page loads. I am getting the "object doesn't support this property or method" error. I must be missing something obvious! Anyone any suggestions?
Here's the code:
HTML Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <form name="myForm" action=" " method="post"> ... </form> <script type="text/javascript"> document.myForm.submit(); </script> </body> </html>
cph.
-
Jul 7, 2008, 13:18 #2
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
Try something like
HTML Code:var theform = document.getElementById('myForm'); theform.submit();
Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Jul 7, 2008, 21:36 #3
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Since the OP has not defined the ID of form tag, I think it is better to do it like this:
Code javascript:var theform = document.myForm; theform.submit();
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Jul 8, 2008, 02:12 #4
- Join Date
- Feb 2008
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for those suggestions Mittineague and rajug, but the object still doesn't want to suport the property/method!
The form works fine when submited with a button, it's just the document.myForm.submit(); line that is producing an error. It doesn't seem to matter what way I write the code (e.g. I have also tried calling a function using the onload event handler).
It's such a simple piece of code that I can't imagine what I'm doing wrong, but it must be something obvious! Anymore suggestions would be welcomed...
cph
-
Jul 8, 2008, 02:38 #5
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What have you put in the action attribute of your form? Give proper your or leave blank if you want to post in the same page.
HTML Code:<form name="myForm" action="" method="post"> ...............
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Jul 8, 2008, 03:13 #6
- Join Date
- Feb 2008
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The action attribute contains the url of the cgi file that handles the form, for the purposes of posting on this forum I left the action attribute blank. The form works perfectly well (it submits with a button), it is the JavaScript code that is producing an error.
-
Jul 8, 2008, 03:29 #7
- Join Date
- Feb 2008
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OK...having said it was the JavaScript...I just tried the code on a different form and it worked fine. So it must be something to do with the form that is causing the JavaScript error.
The form is a PayPal button:
HTML Code:<form name="myForm" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="submit" name="submit" value="Continue"> <img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="item_name" value="Service"> <input type="hidden" name="page_style" value="Primary"> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="lc" value="GB"> <input type="hidden" name="bn" value="PP-SubscriptionsBF"> <input type="hidden" name="a3" value="10.00"> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="M"> <input type="hidden" name="src" value="1"> <input type="hidden" name="sra" value="1"> </form>
-
Jul 8, 2008, 03:50 #8
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This works fine in my case:
HTML Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Auto submit form</title> </head> <body> <form name="myForm" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="submit" name="submit" value="Continue"> <img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="item_name" value="Service"> <input type="hidden" name="page_style" value="Primary"> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="lc" value="GB"> <input type="hidden" name="bn" value="PP-SubscriptionsBF"> <input type="hidden" name="a3" value="10.00"> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="M"> <input type="hidden" name="src" value="1"> <input type="hidden" name="sra" value="1"> </form> <script> document.myForm.submit(); </script> </body> </html>
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Jul 8, 2008, 05:51 #9
- Join Date
- Feb 2008
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Copied that code, but still doesn't autosubmit when I try (tried in IE7 and FF).
Thanks anyway.
-
Jul 8, 2008, 06:07 #10
- Join Date
- Aug 2007
- Location
- Brighton, UK
- Posts
- 2,006
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Oddly, the code that rajug posted only works when I remove the following line:
Code html4strict:<input type="submit" name="submit" value="Continue">
★ James Padolsey
–––––––––––––––––––––––––––––––––––––––
Awesome JavaScript Zoomer (demo here)
'Ajaxy' - Ajax integration solution (demo here)
-
Jul 8, 2008, 06:57 #11
- Join Date
- Feb 2008
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I found it works when I remove that line too. AND interestingly, it also works with:
<input type="image" src="file.gif" border="0" name="submit">
I don't see why using an image instead of a button makes such a difference, but I expect someone out there knows!
Thanks for everyones input on this
Bookmarks