Why does Jquery submit() fail with an error?

Question!

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">
<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>


Answers
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/4652

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

I hope this helps someone else...



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.



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.



This video can help you solving your question :)
By: admin