Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Look at the comments on this site, with a count down. I have done it like this before, and it is simple and effective. Stack&nbsp;Overflow makes good use of color too.</p> <p>Perhaps you don't have enough rep to see the comment box.</p> <p>It runs a little countdown while you type. At it approaches a threshold, the color changes from yellow to red. All using JavaScript, and I assume the keyup event of the textarea.</p> <p>EDIT: How about having it done with jQuery?</p> <pre><code>&lt;script language="javascript" type="text/javascript" src="js/jquery-1.2.6.min.js"&gt;&lt;/script&gt; &lt;script language="javascript" type="text/javascript"&gt; $(document).ready( function () { setMaxLength(); $("textarea.checkMax").bind("click mouseover keyup change", function(){checkMaxLength(this.id); } ) }); function setMaxLength() { $("textarea.checkMax").each(function(i){ intMax = $(this).attr("maxlength"); $(this).after("&lt;div&gt;&lt;span id='"+this.id+"Counter'&gt;"+intMax+"&lt;/span&gt; remaining&lt;/div&gt;"); }); } function checkMaxLength(strID){ intCount = $("#"+strID).val().length; intMax = $("#"+strID).attr("maxlength"); strID = "#"+strID+"Counter"; $(strID).text(parseInt(intMax) - parseInt(intCount)); if (intCount &lt; (intMax * .8)) {$(strID).css("color", "#006600"); } //Good if (intCount &gt; (intMax * .8)) { $(strID).css("color", "#FF9933"); } //Warning at 80% if (intCount &gt; (intMax)) { $(strID).text(0).css("color", "#990000"); } //Over } &lt;/script&gt; </code></pre> <p>And the HTML is</p> <pre><code>&lt;textarea id="text" maxlength="250" class="checkMax"&gt;&lt;/textarea&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload