Thursday, December 16, 2010

How to show number of characters remaining in a text area?? -javascript

<html>

<script type="text/javascript">
  function numberOfCharacters(textbox,limit,indicator) {
    chars = document.getElementById(textbox).value.length;
    document.getElementById(indicator).innerHTML = limit-chars;
  }
</script>

<body>
  <label for="mytextbox">
    Message (140 char. max.)
    <span id="indicator">140</span>
  </label>
  <br/>
  <textarea id="mytextbox" rows="2" cols="40" onkeyup="numberOfCharacters('mytextbox',140,'indicator');"></textarea>
</body>

</html>

1 comment: