<script type="text/javascript"> function CountChars(CharLimit,InputID,OutputID) { var enterchar; var textboxvalue; var remainingchars; enterchar = document.getElementById(InputID).value.length; textboxvalue = document.getElementById(InputID).value; remainingchars = CharLimit - enterchar; document.getElementById(OutputID).innerHTML = remainingchars + " Characters Left(max:156 Characters)"; if (remainingchars <= 0) { document.getElementById(OutputID).innerHTML="0 Characters Left(max:156 Characters)"; alert("you have reached the limit"); document.getElementById(InputID).innerHTML = textboxvalue.substring(0, CharLimit); } } </script>