Monday, September 6, 2010

OnkeyPress attributes in TextBox using JavaScript

Here code shows how to use onkeypress in TextBox.When user write in textbox a Label show no. of charachter entered in TextBox

 function valid(txt,maxLen,lbl1)  
{
lbl1.innerText=(txt.value.length+1);
if(txt.value.length > (maxLen-1))
{
alert("Entered Text reach at its maximum size..!");
return false;
}
}
txtFeedback.Attributes["onkeypress"] = "return valid(this,500," + Label1.ClientID + ")";


Thanks & Regards
Santosh

1 comment:

  1. Hi Santosh

    Your code worked for me.
    Thanks

    ReplyDelete