Textbox maxlength validation and display remaining characters

vishalneeraj-24503
Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 354
Write below Javascript function in ASPX page as:-

function CountCharactersGeneral(sourceTextBox,displayControl,maxLength)
{
if(sourceTextBox != null && displayControl != null)
{
sourceTextBox = document.getElementById(sourceTextBox);
displayControl = document.getElementById(displayControl);

if(sourceTextBox != null)
{
var len = sourceTextBox.value.length;

if (len <= maxLength)
{
displayControl.innerHTML = maxLength -len +" Character(s) remaining.";
}
else
{
sourceTextBox.value = sourceTextBox.value.substring(0,maxLength);
return false;
}
}
}
}


Here is my controls:-
<asp:Label runat="server" ID = "displayControl" Text = ""></asp:Label>
<asp:TextBox ID ="sourceTextBox" runat="server"/>

Comments or Responses

Login to post response