Posted By

assbach on 12/10/06


Tagged

forms chars


Versions (?)

char countdown


 / Published in: JavaScript
 

use to show how many chars are remaining for an input field.

  1. onload="showRemaining(document.forms['myForm'].elements['myInput']);">
  2.  
  3. <script type="text/javascript">
  4. function showRemaining(formElement) {
  5. var theForm = formElement.form;
  6. var remainingDisplay = formElement.name + 'Remaining';
  7. theForm.elements[remainingDisplay].value = formElement.maxLength -
  8. formElement.value.length;
  9. }
  10. </script>
  11. <form name="myForm">
  12. <input type="text" name="myInput" maxlength="20"
  13. onkeyup="showRemaining(this);">
  14. <input type="text" name="myInputRemaining" size="2" readonly>
  15. </form>

Report this snippet  

You need to login to post a comment.