»
EnglishFrenchVietnamese

Print - Input Form Character Limitation - JavaScriptBank.com

Full version: jsB@nk » Form » Validation » Input Form Character Limitation
URL: http://www.javascriptbank.com/input-form-character-limitation.html

Input Form Character Limitation © JavaScriptBank.comYou can use this JavaScript to add a counter of limitation to your inputs such as <input> and <textarea> on your web pages. Just define the limitation for each input, the script does all remaining everything. Very easy to use and customize, let try it now.

Full version: jsB@nk » Form » Validation » Input Form Character Limitation
URL: http://www.javascriptbank.com/input-form-character-limitation.html



JavaScript
<script type="text/javascript">  function text_counter(textfield_id,counter_id,count){    count = parseInt(count);     document.getElementById(counter_id).innerHTML = count;     document.getElementById(textfield_id).onpropertychange = function(){        text_count_changed(textfield_id,counter_id,count);    }  }   function text_count_changed(textfield_id,counter_id,count){    if(count-parseInt(document.getElementById(textfield_id).value.length)<0){        document.getElementById(textfield_id).value = document.getElementById(textfield_id).value.substr(0,count);    }     document.getElementById(counter_id).innerHTML = count-parseInt(document.getElementById(textfield_id).value.length);  }  </script>


HTML
<p><script type="text/javascript">inputtext_approving_chars_count = 10;</script><input type="text" id="inputtext" oninput='text_count_changed("inputtext","inputtext_counter",inputtext_approving_chars_count);'> <span id="inputtext_counter"></span><script type="text/javascript">text_counter("inputtext","inputtext_counter",inputtext_approving_chars_count);</script></p> <p><script type="text/javascript">textfield_approving_chars_count = 255;</script><textarea id="textfield" cols="50" rows="10" oninput='text_count_changed("textfield","textfield_counter",textfield_approving_chars_count);'></textarea> <span id="textfield_counter"></span><script type="text/javascript">text_counter("textfield","textfield_counter",textfield_approving_chars_count);</script></p>