Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi everyone
i am new to jquery and i want to implement a global jquery or javascript function that check whether the text box is empty or not...

What I have tried:

My aspx code is
How can i use jquery or javascript to validate this textbox
ASP.NET
<asp:TextBox ID="txt_Cat_Name" onKeyUp="CheckTextLength(this,15)" onChange="CheckTextLength(this,15)" onkeypress="return isAlfa(event)" runat="server" CssClass="Text"></asp:TextBox>
Posted
Updated 21-Dec-16 21:06pm

1 solution

By writing the script to handle the event, one example will be:
<script>
function CheckTextLength(element, minLength){

	if(element.value.length < minLength){
    	alert("Too short!");
        return false;
    }
}
</script>

and your asp.net control:
ASP.NET
<asp:TextBox ID="txt_Cat_Name" onChange="CheckTextLength(this,15)"  runat="server" CssClass="Text"></asp:TextBox>
 
Share this answer
 
Comments
Muhammd Aamir 22-Dec-16 3:28am    
Peter Leow i am asking about empty text box not about the length of text box kindly help me
Peter Leow 22-Dec-16 3:34am    
Then what is the meaning of the 15 in here:
onChange="CheckTextLength(this,15)"
I already show you an example script, can't you try to understand and figure it out yourself. No effort no gain.
Muhammd Aamir 22-Dec-16 4:06am    
Ok thankx i understand now ....

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