0

I have form and I am using jQuery's validation. It's a test demo.

    <script src="../JS/jquery.js" type="text/javascript"></script>
    <script src="../JS/jquery.validate.js" type="text/javascript"></script>   
    <script language="javascript" type="text/javascript">
        $(function() {
            $("#btns").click(function() {
                if ($("<%=form1.ClientID %>").valid()) {
                    ajaxFunc();//ajax funcion to add email to db
                }

            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>

            <input id="cemail" type="email" name="email" required />
            <input class="submit" type="submit" value="Submit"/>
            <input type="button" id="btns" value="btn"/>
    </div>
    </form>
</body>
</html>

When I use Subimit, the cemail input validate working well(it is showing the validate message and high line the input order).

But when I use button click - doesn't show something. How can I get the same effect when I use button onclick function? Thank you for your help!

Alyona Yavorska
  • 569
  • 2
  • 14
  • 20
willsonchan
  • 200
  • 2
  • 14

1 Answers1

1

You are missing the # in the selector. i.e $("#<%=form1.ClientID %>")

  $(function() {
        $("#btns").click(function() {
            if ($("#<%=form1.ClientID %>").valid()) {
                ajaxFunc();//ajax funcion to add email to db
            }

        });
    });
Sherin Mathew
  • 1,141
  • 13
  • 19