<script language="javascript" type="text/javascript"> /* Set maximum lengthe for textbox using JavaScript with remaining characters This function is used to validate the textbox for the Maximum lengh Parameter: txtBox --> This is the parameter to be passed as a textbox object maxLength --> This parameter is used to pass the Maximum length of the Textbox ------------------------------------------------------------------------------------ We have to call this function for onkeyup and onkeydown events of the textbox or textArea */ function fnClicked(txtBox, maxLength) { //Here we are validating the Length of the Text. //If the text is greater than the provided lenth, we have to ignore the last characters if(txtBox.value.length >= maxLength) { //Removing the last characters which are more than the length txtBox.value = txtBox.value.substring(0, 160); } //Displaying the Remaining characters document.getElementById('lbl').innerHTML = maxLength - txtBox.value.length; } </script>