Code for java script validation

Code for java script validation:


  <script type="text/javascript">
        function Validate() {

            if (document.getElementById("<%=ddlclassId.ClientID%>").value == "0") {
                alert("Please Select Class.");
                document.getElementById('<%=ddlclassId.ClientID%>').focus();
                return false;
            }

            else if (document.getElementById("<%=ddlsubjectid.ClientID%>").value == "0") {
                alert("Please Select Subject.");
                document.getElementById('<%=ddlsubjectid.ClientID%>').focus();
                return false;
            }

            else if (document.getElementById("<%=ddlmonth.ClientID%>").value == "0") {
                alert("Please Select Month.");
                document.getElementById('<%=ddlmonth.ClientID%>').focus();
                return false;
            }
            else if (document.getElementById("<%=txtClassTestname.ClientID%>").value == "") {
                alert("Please Enter Class Name.");
                document.getElementById('<%=txtClassTestname.ClientID%>').focus();
                return false;
            }
            else if (document.getElementById("<%=txtMaxmarks.ClientID%>").value == "") {
                alert("Please Enter Maximum Marks .");
                document.getElementById('<%=txtMaxmarks.ClientID%>').focus();
                return false;
            }
            else if (document.getElementById("<%=TxtPassMarks.ClientID%>").value == "") {
                alert("Please Enter Passing Marks.");
                document.getElementById('<%=TxtPassMarks.ClientID%>').focus();
                return false;
            }
            else if (document.getElementById("<%=txtdate.ClientID%>").value == "") {
                alert("Please Select Date .");
                document.getElementById('<%=txtdate.ClientID%>').focus();
                return false;
            }
            return true;
        }
 
    </script>

Call java script function in to button onclick:

OnClientClick="javaScript:return Validate();"

Other Related  Post:

Comments