Tuesday 6 January 2015

When Textbox text is blank at that time textbox border is red using Jquery

<script src="js/jquery.min.js"></script>

 <script type="text/javascript">
        $(function () {
            $("input[type='text'],Select").bind("keypress blur change", function () {
                if ($(this).val().length > 0) {
                    $(this).css("border-color", "gray");
                }
                else {
                    $(this).css("border-color", "red");
                }
            });

            $("#<%=Btnsave.ClientID%>").click(function (e) {
                if ($("#<%=txtfirstname.ClientID%>").val().length == 0) {
                    $("#<%=txtfirstname.ClientID%>").css("border-color", "red");
                    e.preventDefault();
                }
                else {
                    $("#<%=txtfirstname.ClientID%>").css("border-color", "gray");
                }
                if ($("#<%=txtlastname.ClientID%>").val().length == 0) {
                    $("#<%=txtlastname.ClientID%>").css("border-color", "red");
                    e.preventDefault();
                }
                else {
                    $("#<%=txtlastname.ClientID%>").css("border-color", "gray");
                }
                if ($("#<%=txtCompany.ClientID%>").val().length == 0) {
                    $("#<%=txtCompany.ClientID%>").css("border-color", "red");
                    e.preventDefault();
                }
                else {
                    $("#<%=txtCompany.ClientID%>").css("border-color", "gray");
                }
                if ($("#<%=txtEmailAddress.ClientID%>").val() == 0) {
                    $("#<%=txtEmailAddress.ClientID%>").css("border-color", "red");
                    e.preventDefault();
                }
                else {
                    $("#<%=txtEmailAddress.ClientID%>").css("border-color", "gray");
                }

            });

        });

    </script>

No comments:

Post a Comment