JS - Blank Validation & Length

<html>
    <head>
        <script type="text/javascript">
        function validate()
        {
            var a = document.getElementById("name").value;
            if(a.length==0)
            {
                document.getElementById("warning").innerHTML="Please enter your name";
            }
            if(a.length!=0)
            {
                document.getElementById("warning").innerHTML="";
                document.getElementById("success").innerHTML="Length of your name is "+a.length;
            }
        }
         </script>
    </head>
    <body>
    <style>
        div
        {
            color:#ff0000;
        }
    </style>
    <h3 align="center">Blank Validation & Length Validation </h1>
    <label>Enter your name:</label>
    <input type="text" id="name"/><div id="warning"> </div>
    <input type="Submit" id="validate" value="validate" onclick="validate()"/>
    <div id="success"> </div>
    </body>
</html>

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.