JQuery validation works with the input type = "submit" element, but not with the html element. What for?

Using ASP.NET, why does this mean that the bassistance.de jQuery validation plugin prevents form submissions when using input type = "submit" elements rather than html button elements?

Validation is done using the html tag (type = "submit"), but the form is still submitted.

Is there a way to get the jQuery validation plugin to work with html button elements?

Quick example:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <script type="text/javascript">
            $(document).ready(function () {
                $("#form1").validate({
                    rules: {
                        txtFirstName: {
                            required: true
                        }
                    },
                    messages: {
                        txtFirstName: {
                            required: "* First Name required<br/>"
                        }
                    }
                });
            });
        </script>
    </head>

    <body>
        <form id="form1" runat="server">
            <input id="txtFirstName" name="txtFirstName" type="text" />
            <input id="btnSubmit1" type="submit" runat="server" value="Submit" /> <!-- WORKS! -->
            <button it="btnSubmit2" type="submit" runat="server">Submit</button> <!-- DOESN'T WORK -->
        </form>
    </body>
</html>
+3
source share
1 answer

It seems to be designed this way:

// when a submitHandler is used, capture the submitting button
if (validator.settings.submitHandler) {
  inputsAndButtons.filter(":submit").click(function () {
    validator.submitButton = this;
  });
}

Unfortunately, it looks like it is baked, with no other option. The documentation on :selectseems to shed some light on this:

:submit . , type="default" , (, Internet Explorer) .

button , . , :

$("#myform").validate();
$("a.check").click(function() {
  $("#myform").valid();
});
+5

All Articles