views:

755

answers:

4

I have a simple form on a page and I want to auto submit it when some event occurs.

The test code below tries to submit the form as soon as the page loads, but it fails. Firebug says that "H[G] is not a function". H[G] appears to be "submit".

Am I doing something really obviously stupid?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>test</title>
</head>
<body>
    <form action="/test.php" method="post" id="packingform">
        <input name="bob" value="1" type="text" />
        <input type="submit" name="submit" value="hello" />
    </form>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script type="text/javascript">
    // <![CDATA[
    $(document).ready(function() 
    {
        // This line fails with an error and the form is not submitted
        $("#packingform").submit();
    }
    );
    // ]]>
    </script>
</body>
</html>
A: 

The problem seems to be with action="/test.php"on Firefox, because it works on both Chrome and IE

Try changing it to action="test.php" and try again.

Andreas Grech
nope, that did not effect the behaviour
rikh
when i set the action to test.php, the form submitted here
Andreas Grech
what jquery version are u using by any chance? I tried it with 1.3.2
Andreas Grech
A: 

My guess is that there is something wrong with your jQuery.js file. Maybe try replacing the jQuery.js file with a fresh copy downloaded from the jQuery website.

Philippe Leybaert
+2  A: 

Got it.

Turns out that if you have a named submit button in your form, submit() will fail. Here is a link to the bug report on jquery: http://dev.jquery.com/ticket/4653

The solution is to change <input type="submit" name="submit" value="hello" />
to <input type="submit" value="hello" />

I hope this helps someone else...

rikh
...the form is still not posting in FF with the "/" in 'action'...or is this only happening on my pc ?
Andreas Grech
and as regards the naming issue, the problem is only when the submit button is named "submit"; if it's named something else, the form still posts without any trouble
Andreas Grech
All feels a bit flaky to me. I might have to look at jQuery's source to figure out why it would be so sensitive. It worked in FF and Safari here when I changed the submit name, and those are the only 2 browsers I need to support for this project (internal).
rikh
A: 

hi it is great indeed very helpfull, i wasted around 16 hours looking at what happend and the solution was to change name of submit button thanks

constantine stanley