/ Published in: JavaScript
URL: http://www.webcodingtech.com/javascript/limit-input-text.php
Expand |
Embed | Plain Text
HTML --------- <form> <textarea cols=100 rows=20 onkeyup="change(this);"></textarea> <br>You've typed <span id="char_cnt">0</span> character(s). You are allowed <span id="chars_left">lots</span> more. </form> --------- JAVASCRIPT --------- <script type="text/javascript"> function change (el) { var max_len = 10; if (el.value.length > max_len) { el.value = el.value.substr(0, max_len); } document.getElementById('char_cnt').innerHTML = el.value.length; document.getElementById('chars_left').innerHTML = max_len - el.value.length; return true; } </script> ---------
You need to login to post a comment.
