Friday, September 30, 2011

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