Textbox require field validation using javascript

Form validation is very important, we will use textboxs in many places. we have to do client side validation using javascript. I am showing one example here. After click on button, if textbox value is empty. this will show alert "please enter name".




<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function ValidateForm() {
            var txtName = document.getElementById("txtName").value;
            if (txtName == '')
                alert("please enter name");
        }
    </script>
</head>
<body>
Name: <input type="text" id="txtName" /><br />
<br />
<input type='button' value="validate" onclick="ValidateForm();" />

</body>
</html>

If you have any queries or suggestions, please feel free to ask in comments section.
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar