<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:series="http://unfoldingneurons.com/"
		>
<channel>
	<title>Comments on: Limit Characters in a Textarea with Prototype</title>
	<atom:link href="http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/</link>
	<description>web development, photography, tutorials and adventure</description>
	<lastBuildDate>Tue, 16 Mar 2010 18:09:05 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jeremy Jackson</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/comment-page-1/#comment-2349</link>
		<dc:creator>Jeremy Jackson</dc:creator>
		<pubDate>Sat, 25 Apr 2009 17:27:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-2349</guid>
		<description>&lt;p&gt;I reworked this code to better fit into a class that I was working on. Thanks for the example.&lt;/p&gt;

&lt;p&gt;[code]
  /* Makes all textareas with a &quot;limited&quot; class limit the number of characters
   * that are allowed to be entered in it.  It will update the number of chars
   * left in a given textarea with the [textarea.id]&lt;em&gt;counter id set on it.  The
   * number of characters it will restrict to is pulled from the title, so if
   * you want a 200 char limit, put something like &quot;200 character limit&quot; in the
   * title attribute (defaults to 100 if unable to parse one).
   */
  makeTextareasLimitInput: function() {
    $$(&#039;textarea.limited&#039;).each(function(textarea) {
      var limitInput = function(event) {
        var element = Event.element(event), limit = parseInt(element.title) &#124;&#124; 100;
        if (element.value.length &gt;= limit) element.value = element.value.substring(0, limit);
        if (counter = (element.id) ? $(element.id + &#039;&lt;/em&gt;counter&#039;) : false) {
          var charsLeft = (limit - element.value.length);
          counter.update(charsLeft + ((charsLeft == 1) ? &#039; character &#039; : &#039; characters &#039;) + &#039;left&#039;);
          if (charsLeft) counter.removeClassName(&#039;max-reached&#039;);
          else counter.addClassName(&#039;max-reached&#039;);
        }
      }
      $w(&#039;keyup keydown blur&#039;).each(function(eventName) {
            textarea.observe(eventName, limitInput, false);
      });
    });
  },
[/code]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I reworked this code to better fit into a class that I was working on. Thanks for the example.</p>

<p>[code]
  /* Makes all textareas with a "limited" class limit the number of characters
   * that are allowed to be entered in it.  It will update the number of chars
   * left in a given textarea with the [textarea.id]<em>counter id set on it.  The
   * number of characters it will restrict to is pulled from the title, so if
   * you want a 200 char limit, put something like "200 character limit" in the
   * title attribute (defaults to 100 if unable to parse one).
   */
  makeTextareasLimitInput: function() {
    $$('textarea.limited').each(function(textarea) {
      var limitInput = function(event) {
        var element = Event.element(event), limit = parseInt(element.title) || 100;
        if (element.value.length &gt;= limit) element.value = element.value.substring(0, limit);
        if (counter = (element.id) ? $(element.id + '</em>counter') : false) {
          var charsLeft = (limit - element.value.length);
          counter.update(charsLeft + ((charsLeft == 1) ? ' character ' : ' characters ') + 'left');
          if (charsLeft) counter.removeClassName('max-reached');
          else counter.addClassName('max-reached');
        }
      }
      $w('keyup keydown blur').each(function(eventName) {
            textarea.observe(eventName, limitInput, false);
      });
    });
  },
[/code]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: gioco ai casinò online</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/comment-page-1/#comment-2344</link>
		<dc:creator>gioco ai casinò online</dc:creator>
		<pubDate>Mon, 20 Apr 2009 12:14:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-2344</guid>
		<description>&lt;p&gt;I am using TinyMCE editor for textarea.how to limit the characters in that textarea.500 is limit for that textarea,how to limit characters for this textarea in client side.alert message after 500 characters or displaying dynamic count of characters above the text area.thanks&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I am using TinyMCE editor for textarea.how to limit the characters in that textarea.500 is limit for that textarea,how to limit characters for this textarea in client side.alert message after 500 characters or displaying dynamic count of characters above the text area.thanks</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Franco Sabbatini</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/comment-page-1/#comment-2253</link>
		<dc:creator>Franco Sabbatini</dc:creator>
		<pubDate>Tue, 20 Jan 2009 11:35:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-2253</guid>
		<description>&lt;p&gt;i forgot to mention:
i added a // to the line i changed&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>i forgot to mention:
i added a // to the line i changed</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Franco Sabbatini</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/comment-page-1/#comment-2252</link>
		<dc:creator>Franco Sabbatini</dc:creator>
		<pubDate>Tue, 20 Jan 2009 11:06:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-2252</guid>
		<description>&lt;p&gt;Hi there! so i really loved your code :) because im a fun of prototype like you :).. 
i made a change to your code that i get everyone would love to have:
  The PROBLEM: when you changed the textarea value by javascript (lets say innerHTML=&#039;hola amigo&#039;) this code would not work due the lack of a CHANGE event. So when i tried CHANGE event didnt work either &#039;cause changing the value other way than clicking on it WILL NOT FIRE THE EVENT EITHER!
 the SOLUTION: just added a nice timer to it :) (a timed observer)
so here is the code&lt;/p&gt;

&lt;p&gt;[code]
/* &lt;/p&gt;

&lt;p&gt;Title :     charcount.js
Author :        Terri Ann Swallow
URL :       http://www.ninedays.org/
Project :       Ninedays Blog
Copyright:      (c) 2008 Sam Stephenson
            This script is is freely distributable under the terms of an MIT-style license.&lt;/p&gt;

&lt;p&gt;Description :   Functions in relation to limiting and displaying the number of characters allowed in a textarea
Version:        2.1
Changes:        Added overage override.  Read blog for updates: http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/&lt;/p&gt;

&lt;p&gt;Created :       1/17/2008 - January 17, 2008
Modified :      5/20/2008 - May 20, 2008&lt;/p&gt;

&lt;p&gt;Functions:      init()                      Function called when the window loads to initiate and apply character counting capabilities to select textareas
            charCounter(id, maxlimit, limited)  Function that counts the number of characters, alters the display number and the calss applied to the display number
            contarCaracteres(id, maxsize, limited)  Function called in the init() function, sets the listeners on teh textarea nd instantiates the feedback display number if it does not exist&lt;/p&gt;

&lt;p&gt;Modified: 1/20/2009
Author of modification: Franco Sabbatini
Changes: if innerHTML is inserted with javascript then KeyUp and KeyDown would not work. Added a timer&lt;/p&gt;

&lt;p&gt;*/
    Event.observe(window, &#039;load&#039;, init);
    function init(){
        contarCaracteres(&#039;txtComentario&#039;,10);
    }&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function charCounter(id, maxlimit, limited){
    if (!$(&#039;counter-&#039;+id)){
        $(id).insert({after: &#039;&lt;div id=&quot;counter-&#039;+id+&#039;&quot;&gt;&lt;/div&gt;&#039;});
    }
    if($F(id).length &gt;= maxlimit){
        if(limited){    $(id).value = $F(id).substring(0, maxlimit); }
        $(&#039;counter-&#039;+id).addClassName(&#039;charcount-limit&#039;);
        $(&#039;counter-&#039;+id).removeClassName(&#039;charcount-safe&#039;);
    } else {    
        $(&#039;counter-&#039;+id).removeClassName(&#039;charcount-limit&#039;);
        $(&#039;counter-&#039;+id).addClassName(&#039;charcount-safe&#039;);
    }
    $(&#039;counter-&#039;+id).update( $F(id).length + &#039;/&#039; + maxlimit );  

}

function contarCaracteres(id, maxsize, limited){
    if(limited == null) limited = true;
    if ($(id)){
        //new Form.Element.Observer($(id), 0.2, function(){charCounter(id, maxsize, limited);});
        Event.observe($(id), &#039;keyup&#039;, function(){charCounter(id, maxsize, limited);}, false);
        Event.observe($(id), &#039;keydown&#039;, function(){charCounter(id, maxsize, limited);}, false);
        charCounter(id,maxsize,limited);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;[/code]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi there! so i really loved your code :) because im a fun of prototype like you :).. 
i made a change to your code that i get everyone would love to have:
  The PROBLEM: when you changed the textarea value by javascript (lets say innerHTML=&#8217;hola amigo&#8217;) this code would not work due the lack of a CHANGE event. So when i tried CHANGE event didnt work either &#8217;cause changing the value other way than clicking on it WILL NOT FIRE THE EVENT EITHER!
 the SOLUTION: just added a nice timer to it :) (a timed observer)
so here is the code</p>

<p>[code]
/* </p>

<p>Title :     charcount.js
Author :        Terri Ann Swallow
URL :       <a href="http://www.ninedays.org/" rel="nofollow">http://www.ninedays.org/</a>
Project :       Ninedays Blog
Copyright:      (c) 2008 Sam Stephenson
            This script is is freely distributable under the terms of an MIT-style license.</p>

<p>Description :   Functions in relation to limiting and displaying the number of characters allowed in a textarea
Version:        2.1
Changes:        Added overage override.  Read blog for updates: <a href="http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/" rel="nofollow">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/</a></p>

<p>Created :       1/17/2008 - January 17, 2008
Modified :      5/20/2008 - May 20, 2008</p>

<p>Functions:      init()                      Function called when the window loads to initiate and apply character counting capabilities to select textareas
            charCounter(id, maxlimit, limited)  Function that counts the number of characters, alters the display number and the calss applied to the display number
            contarCaracteres(id, maxsize, limited)  Function called in the init() function, sets the listeners on teh textarea nd instantiates the feedback display number if it does not exist</p>

<p>Modified: 1/20/2009
Author of modification: Franco Sabbatini
Changes: if innerHTML is inserted with javascript then KeyUp and KeyDown would not work. Added a timer</p>

<p>*/
    Event.observe(window, 'load', init);
    function init(){
        contarCaracteres('txtComentario',10);
    }</p>

<pre><code>function charCounter(id, maxlimit, limited){
    if (!$('counter-'+id)){
        $(id).insert({after: '&lt;div id="counter-'+id+'"&gt;&lt;/div&gt;'});
    }
    if($F(id).length &gt;= maxlimit){
        if(limited){    $(id).value = $F(id).substring(0, maxlimit); }
        $('counter-'+id).addClassName('charcount-limit');
        $('counter-'+id).removeClassName('charcount-safe');
    } else {    
        $('counter-'+id).removeClassName('charcount-limit');
        $('counter-'+id).addClassName('charcount-safe');
    }
    $('counter-'+id).update( $F(id).length + '/' + maxlimit );  

}

function contarCaracteres(id, maxsize, limited){
    if(limited == null) limited = true;
    if ($(id)){
        //new Form.Element.Observer($(id), 0.2, function(){charCounter(id, maxsize, limited);});
        Event.observe($(id), 'keyup', function(){charCounter(id, maxsize, limited);}, false);
        Event.observe($(id), 'keydown', function(){charCounter(id, maxsize, limited);}, false);
        charCounter(id,maxsize,limited);
    }
}
</code></pre>

<p>[/code]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Knal</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/comment-page-1/#comment-1974</link>
		<dc:creator>Knal</dc:creator>
		<pubDate>Mon, 01 Dec 2008 22:48:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1974</guid>
		<description>&lt;p&gt;Ok, thanks.&lt;/p&gt;

&lt;p&gt;The simplified form looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&lt;form id=&quot;contactform&quot; action=&quot;contact.php&quot; method=&quot;post&quot;&gt;
    &lt;label for=&quot;msg&quot;&gt;Message&lt;/label&gt;: &lt;span&gt;(&lt;span id=&quot;counter-msg&quot;&gt;&lt;b&gt;300&lt;/b&gt;&lt;/span&gt; Chars)&lt;/span&gt;     
    &lt;textarea name=&quot;msg&quot; id=&quot;msg&quot; cols=&quot;40&quot; rows=&quot;4&quot;&gt;&lt;/textarea&gt;
    &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
    &lt;input type=&quot;reset&quot; id=&quot;resetform&quot; name=&quot;Reset&quot; value=&quot;Reset&quot; /&gt;
&lt;/form&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The javascript looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var valid = new Validation( &#039;contactform&#039;, { immediate : false, onFormValidate : HandleForm });
Validation.addAllThese([ [&#039;msg&#039;, &#039;Bitte, Foobar&#039;, { minLength : 3, maxLength : 100, include : [&#039;required&#039;] }] ]);
$(&#039;resetform&#039;).observe(&#039;click&#039;, function (){ valid.reset(); init(); }); 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Thanks again for your help!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Ok, thanks.</p>

<p>The simplified form looks like this:</p>

<pre><code>&lt;form id="contactform" action="contact.php" method="post"&gt;
    &lt;label for="msg"&gt;Message&lt;/label&gt;: &lt;span&gt;(&lt;span id="counter-msg"&gt;&lt;b&gt;300&lt;/b&gt;&lt;/span&gt; Chars)&lt;/span&gt;     
    &lt;textarea name="msg" id="msg" cols="40" rows="4"&gt;&lt;/textarea&gt;
    &lt;input type="submit" value="Submit" /&gt;
    &lt;input type="reset" id="resetform" name="Reset" value="Reset" /&gt;
&lt;/form&gt;
</code></pre>

<p>The javascript looks like this:</p>

<pre><code>var valid = new Validation( 'contactform', { immediate : false, onFormValidate : HandleForm });
Validation.addAllThese([ ['msg', 'Bitte, Foobar', { minLength : 3, maxLength : 100, include : ['required'] }] ]);
$('resetform').observe('click', function (){ valid.reset(); init(); }); 
</code></pre>

<p>Thanks again for your help!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Terri Ann</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/comment-page-1/#comment-1973</link>
		<dc:creator>Terri Ann</dc:creator>
		<pubDate>Mon, 01 Dec 2008 22:13:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1973</guid>
		<description>&lt;p&gt;When you submit your code use your preferred code edito to tab in the content you want to display as code and leave an empty line between your comments and code.&lt;/p&gt;

&lt;p&gt;example:&lt;/p&gt;

&lt;p&gt;blah blah blah blah&lt;/p&gt;

&lt;p&gt;[tab] code code code
[tab] code code code&lt;/p&gt;

&lt;p&gt;Then I&#039;ll take a look again!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>When you submit your code use your preferred code edito to tab in the content you want to display as code and leave an empty line between your comments and code.</p>

<p>example:</p>

<p>blah blah blah blah</p>

<p>[tab] code code code
[tab] code code code</p>

<p>Then I&#8217;ll take a look again!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Knal</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/comment-page-1/#comment-1971</link>
		<dc:creator>Knal</dc:creator>
		<pubDate>Mon, 01 Dec 2008 17:51:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1971</guid>
		<description>&lt;p&gt;Apparently my form in my comment was filtered out...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Apparently my form in my comment was filtered out&#8230;</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Knal</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/comment-page-1/#comment-1970</link>
		<dc:creator>Knal</dc:creator>
		<pubDate>Mon, 01 Dec 2008 17:50:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1970</guid>
		<description>&lt;p&gt;I&#039;ve aded the init();, but it only works if i click twice.
My simplified code looks like this:&lt;/p&gt;

&lt;p&gt;
  var valid = new Validation( &#039;contactform&#039;, { immediate : false, onFormValidate : HandleForm });&lt;/p&gt;

&lt;p&gt;Validation.addAllThese([
  [&#039;msg&#039;, &#039;Bitte, Foobar&#039;, { minLength : 3, maxLength : 100, include : [&#039;required&#039;] }]
  ]);&lt;/p&gt;

&lt;p&gt;$(&#039;resetform&#039;).observe(&#039;click&#039;, 
    function (){
      valid.reset();
      init();
  });
&lt;/p&gt;

&lt;p&gt;Hope you can help.&lt;/p&gt;

&lt;p&gt;Thanks, Knal&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I&#8217;ve aded the init();, but it only works if i click twice.
My simplified code looks like this:</p>

<p>
  var valid = new Validation( &#8216;contactform&#8217;, { immediate : false, onFormValidate : HandleForm });</p>

<p>Validation.addAllThese([
  ['msg', 'Bitte, Foobar', { minLength : 3, maxLength : 100, include : ['required'] }]
  ]);</p>

<p>$(&#8216;resetform&#8217;).observe(&#8216;click&#8217;, 
    function (){
      valid.reset();
      init();
  });
</p>

<p>Hope you can help.</p>

<p>Thanks, Knal</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Terri Ann</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/comment-page-1/#comment-1964</link>
		<dc:creator>Terri Ann</dc:creator>
		<pubDate>Mon, 01 Dec 2008 03:07:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1964</guid>
		<description>&lt;p&gt;Best suggestion would be to add a trigger using the really easy validation, or call the &lt;code&gt;makeItCount()&lt;/code&gt; or &lt;code&gt;init()&lt;/code&gt; onreset.&lt;/p&gt;

&lt;p&gt;Good luck - feel free to repost your findings!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Best suggestion would be to add a trigger using the really easy validation, or call the <code>makeItCount()</code> or <code>init()</code> onreset.</p>

<p>Good luck &#8211; feel free to repost your findings!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Knal</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/comment-page-1/#comment-1961</link>
		<dc:creator>Knal</dc:creator>
		<pubDate>Sat, 29 Nov 2008 17:00:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1961</guid>
		<description>&lt;p&gt;I have combined this functionality with the  Really Easy validation and coma across a small problem:
If i reset a form (), the counter does not reset since it isn&#039;t triggered.
Any ideas?&lt;/p&gt;

&lt;p&gt;Thanks a load!&lt;/p&gt;

&lt;p&gt;Knal.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I have combined this functionality with the  Really Easy validation and coma across a small problem:
If i reset a form (), the counter does not reset since it isn&#8217;t triggered.
Any ideas?</p>

<p>Thanks a load!</p>

<p>Knal.</p>]]></content:encoded>
	</item>
</channel>
</rss>
