Use a different name for the submit-button. Using name="submit" you override
the actual submit-function of the form. Keep in mind that in the DOM API,
you can access any form element as a property of the form, referenced by
name.

Jörn

On Thu, Nov 12, 2009 at 8:48 PM, mcrawford <mcrawf...@gmail.com> wrote:

> I'm totally stumped with the submitHandler. Here is my test page, down
> below. I'm using PHP just to print out the form variables but
> obviously you could adapt the HTML for anything.
>
> Notice that I have set my Submit button to have name="submit" which
> means that, in the submitHandler, form.submit() is not a function. I
> get a JavaScript error on that line, but (and this is what I can't
> figure out), the form still submits.
>
> I can change the Submit button to have a different name, like
> name="sbmt". That avoids the JS error on the form.submit() line. But
> then (and I don't get this either), if you click the Cancel button,
> that value of cancel=Cancel will not get sent in the post. With the
> Submit button named "submit" the cancel=Cancel gets posted correctly
> when you click on that button.
>
> <?php
> if (!empty($_POST)) {
>        print_r($_POST);
> }
> ?>
>
> <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
>        <head>
>                <title>TEST</title>
>                <meta http-equiv="Content-Type" content="text/html;
> charset=utf-8"/>
>                <script type="text/javascript"
> src="/js/jquery-1.3.2.js"></script>
>                <script type="text/javascript" src="/js/jquery-validate/
> jquery.validate.js"></script>
>        </head>
>        <body>
>                <form action="test-validate.php" method="post"
> id="the-form">
>                        <input type="hidden" name="hidden"
> value="something"/>
>                        <input class="button" type="submit" name="submit"
> value="Do it
> now!"/>
>                        <input class="button cancel" type="submit"
> name="cancel"
> value="Cancel"/>
>                </form>
>                <script type="text/javascript">
>                        $(function() {
>                                // VALIDATION
>                                $("#the-form").validate({
>                                        submitHandler: function(form) {
>                                                $('input[name=submit]',
> '#the-form').attr('disabled',
> 'disabled');
>                                                form.submit();
>                                        }
>                                });
>                        });
>                </script>
>        </body>
> </html>
>
>

Reply via email to