Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i want to make validation whether user has entered something or not in textbox as sooon as he presses TAB key
if the textbox is blank and presses TAB key then i want validation in javascript that can not empty and event as onlostFocus in ASP.net
plz help
Posted

try

XML
<script type="text/javascript">
    function validate(c)
        {
            if(c.value=="")
            {
                alert("The required field cannot left blank");
                c.focus();
            }
        }
</script>

<asp:TextBox ID="TextBox1" runat="server" onblur="validate(this)"></asp:TextBox>
 
Share this answer
 
Comments
Sachin MCA2012 8-Feb-14 3:46am    
but if the user click on other area still this message display how i can prevent this
try this for tab key..

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="jquery-1.10.2.js" type="text/javascript"></script>
    <script type="text/javascript">


        function validate(e, txt) {
            var KeyID = e.keyCode;
            if (KeyID == 9) {
                if (txt.value == '')
                    alert('Please enter the field..');
                txt.focus();
                return false;
            }
        }

    </script>
</head>
<body>
    <form id="frm" runat="server">
    <asp:TextBox ID="txtbox" onkeydown="return validate(event,this);" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox1"   runat="server"></asp:TextBox>
    </form>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900