Knowledge Walls
John Peter
Pune, Maharashtra, India
How to validate textbox using javascript with Example
3887 Views
Example
<html>
    <head>
        <title>getElementsByName example</title>
        <script type="text/javascript">
            function validate(){
                if (document.getElementById("txt_username").value == ""){
                   alert("Enter the username");
                   document.getElementById("txt_username").focus();
                }
                else {
                   alert("Everything Okay");
                }
            }
        </script>
    </head>
    <body>
        Username: <input type="text" id="txt_username" />
        <button onclick="javascript:validate();">Validate</button>
    </body>
</html>
Demo & Output 
Best Lessons of "Good Javascript Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details