Monday, February 16, 2015

Validate Multiple Textboxes, Check boxes using jquery(Eg Textbox)

<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
        <input id="btnSubmit" type="button" value="button" />
    </div>
    </form>
</body>



<head runat="server">
    <title></title>
    <script type="text/javascript"></script>
    <script src="Jquery.js"></script>
    <script src="JavaScript2.js"></script>

</head>


Javascript2.js

$(document).ready(function () {
    $('#btnSubmit').click(function (e) {
        var isValid = true;
        $('input[type="text"]').each(function () {
            if ($.trim($(this).val()) == ' ') {
                isValid = false;
                $(this).css({
                    "border": "2px solid blue",
                    "background": "#FFCERE"
                });
            }
            else {
                $(this).css({
                    "border": "",
                    "background": ""
                });
            }
        });
        if (isValid == false)
            e.preventDefault();
        else
            alert('Thank you ');
    });
});


Output:





To Validate all Check Boxes

$("input[type='checkbox']:checked").each(

            function () {
});

No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...