jQuery - automatically submitting a form

I’m sure this is really easy, but I can’t get it to work :frowning:

I’m trying to submit a form full of hidden fields automatically when the page loads. I don’t have access to the <body> tag, so I’m trying to add the auto submit with javascript. (jqeury)

I’ve got so far:

<form id="paypalpayment" name="paypalpayment" action="https://www.paypal.com/cgi-bin/webscr" method="post">
//bunch of hidden form fields
<input name="submit" type="submit" id="submit" value="Click to continue if you are not automatically redirected." />

<script type="text/javascript">
jQuery(document).ready(function($) {

But nothing happens…

Any suggestions?

btw this is within a wordpress page.

i’ve tried the regular “$(document).ready(function() {” as well.

It will be much easier for us to debug your problem if we can examine the page that’s having trouble.

Unfortunately this is on my local server

What does your browser’s error console / javascript console (what browser are you testing with) have to say regarding this?


Showing no error.

I added a debug paragraph <p> and changed the javascript to:
$(document).ready(function() {
$(“p”).text(“We are here”);

The last line of the javascript modifies the added debug paragraph without any troubles, suggesting the .submit() line isn’t causing an error, just does nothing.

You can’t alway just drop code into a WordPress theme file and have it work. Did you use wp_enqueue_script(“jquery”); ??

and if you are using other javascript libraries (i.e. prototype), you should use jquery in “no conflict” mode. i.e. $j instead of $

Not sure what wp_enqueue_script is (I need to check that)

I think it is in “no conflict” mode, was just a free theme Im using

I’ve uploaded it live:

Without a <body> tag document object references won’t work. Try…

// do stuff here

$(“paypalpayment”) looks for html elements like <paypalpayment>

You probably meant to find an element by id.


Thx for your responses. U are correct crmalibu, thats what I meant.

Ive tried changing live site to $(window) and corrected to #paypalpayment and still isnt working for me.

$(window).load(function () {
// run code

May actually be more suited to your needs…

Thanks for the suggestion, changing to “load” didn’t solve the problem.

load and ready event handlers tend to conflict allot… I wold suggest adding the load event to the element…

<form id=“paypalpayment” name=“paypalpayment” action=“https://www.paypal.com/cgi-bin/webscr” method=“post”>
//bunch of hidden form fields
<input name=“submit” type=“submit” id=“submit” value=“Click to continue if you are not automatically redirected.” />

<script type=“text/javascript”>
$(“#paypalpayment”).load(function($) {

Getting some weird error:
Error: syntax error
Source File: …/paypal-payment-submit/
Line: 105, Column: 29
Source Code:

I think you are editing in the design view… hence the <p></p> inserts in between your script tags… You might want to switch to code view and remove those tags…

Interesting, I wasn editing in HTML view not Visual view.
Anyway i’ve removed all line spaces from javascript code.
No error now, but still doesn’t work.

How would you suggest that we duplicate in some way your situation, so that instead stabbing blindly in the dark, someone here can actually help you.

Hi pmw57

I did upload it and put a link to it earlier, see http://tinyurl.com/yhvulfu

I’m seeing conflicts with the submit button that’s also called submit.

Try this instead to see if it works as a work-around.