<?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"
	>
<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>
	<pubDate>Tue, 06 Jan 2009 06:06:49 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
		<item>
		<title>By: Knal</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#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;&#60;form id="contactform" action="contact.php" method="post"&#62;
    &#60;label for="msg"&#62;Message&#60;/label&#62;: &#60;span&#62;(&#60;span id="counter-msg"&#62;&#60;b&#62;300&#60;/b&#62;&#60;/span&#62; Chars)&#60;/span&#62;     
    &#60;textarea name="msg" id="msg" cols="40" rows="4"&#62;&#60;/textarea&#62;
    &#60;input type="submit" value="Submit" /&#62;
    &#60;input type="reset" id="resetform" name="Reset" value="Reset" /&#62;
&#60;/form&#62;
&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( 'contactform', { immediate : false, onFormValidate : HandleForm });
Validation.addAllThese([ ['msg', 'Bitte, Foobar', { minLength : 3, maxLength : 100, include : ['required'] }] ]);
$('resetform').observe('click', 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-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'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'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-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...</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-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'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( 'contactform', { immediate : false, onFormValidate : HandleForm });&lt;/p&gt;

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

&lt;p&gt;$('resetform').observe('click', 
    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've aded the init();, but it only works if i click twice.
My simplified code looks like this:</p>

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

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

<p>$('resetform').observe('click', 
    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-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 - 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-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'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't triggered.
Any ideas?</p>

<p>Thanks a load!</p>

<p>Knal.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Mark McKay</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1142</link>
		<dc:creator>Mark McKay</dc:creator>
		<pubDate>Thu, 17 Jul 2008 01:18:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1142</guid>
		<description>&lt;p&gt;Great script.&lt;/p&gt;

&lt;p&gt;If you place the  containing the remaining characters in the Label your approach will be more accessible to screen readers as they only speak labels when in forms mode.&lt;/p&gt;

&lt;p&gt;i.e.&lt;/p&gt;

&lt;p&gt;Description (0/300
characters)&lt;/p&gt;

&lt;p&gt;Mark&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Great script.</p>

<p>If you place the  containing the remaining characters in the Label your approach will be more accessible to screen readers as they only speak labels when in forms mode.</p>

<p>i.e.</p>

<p>Description (0/300
characters)</p>

<p>Mark</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Milos</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1140</link>
		<dc:creator>Milos</dc:creator>
		<pubDate>Wed, 16 Jul 2008 06:36:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1140</guid>
		<description>&lt;p&gt;Hello!
according to Phillips post I have updatet your script to output a message or to color the letters when a maximum limit of letters is reached. &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function charCounter(id, maxlimit, limited){
    if (!$('counter-'+id)){
        $(id).insert({after: '&#60;div id="counter-'+id+'"&#62;&#60;/div&#62;'});
    }
    if($F(id).length &#62;= 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 + ' von ' + maxlimit );
    // here is the updated Code START
    if ($F(id).length &#62; 25) {
    // do here what ever you want if the limit is reached
    alert("Maximum letters are reached. ...");
    }
    // here is the updated Code END
}
&lt;/code&gt;&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>Hello!
according to Phillips post I have updatet your script to output a message or to color the letters when a maximum limit of letters is reached. </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 + ' von ' + maxlimit );
    // here is the updated Code START
    if ($F(id).length &gt; 25) {
    // do here what ever you want if the limit is reached
    alert("Maximum letters are reached. ...");
    }
    // here is the updated Code END
}
</code></pre>]]></content:encoded>
	</item>
	<item>
		<title>By: Paolo Gabrielli</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1064</link>
		<dc:creator>Paolo Gabrielli</dc:creator>
		<pubDate>Thu, 10 Jul 2008 17:45:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-1064</guid>
		<description>&lt;p&gt;Thanks for your code.
Just a line to ask your help: if I (copy &#38;) paste into the textarea the field is not updated. I searched around the net but I haven't find anything. The only solution that I came with is to use
new &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Form.Element.Observer($(id), 0.5, function(){charCounter(id, maxsize, limited);})
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;instead of the 2 Event.observe.
Every 500ms it check if the textarea is changed and even if you copy&#38;paste it updates the counter.
Many thanks,
P.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks for your code.
Just a line to ask your help: if I (copy &amp;) paste into the textarea the field is not updated. I searched around the net but I haven't find anything. The only solution that I came with is to use
new </p>

<pre><code>Form.Element.Observer($(id), 0.5, function(){charCounter(id, maxsize, limited);})
</code></pre>

<p>instead of the 2 Event.observe.
Every 500ms it check if the textarea is changed and even if you copy&amp;paste it updates the counter.
Many thanks,
P.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Marc Falk</title>
		<link>http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-655</link>
		<dc:creator>Marc Falk</dc:creator>
		<pubDate>Wed, 18 Jun 2008 02:49:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ninedays.org/2008/01/17/limit-characters-in-a-textarea-with-prototype/#comment-655</guid>
		<description>&lt;p&gt;Ah crap, hadn't noticed that html tags was allowed here. They used to be forbidden with a big F! :P&lt;/p&gt;

&lt;p&gt;Anyway , I wanted to know if you could limit other elements, like div, span and p with your script... and I've actually found a way to do it now with the prototype truncate string.&lt;/p&gt;

&lt;p&gt;At the moment I'm just using:&lt;/p&gt;

&lt;p&gt;Script:
&lt;code&gt;$('truncate').update($('truncate').innerHTML.truncate(10))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Content:
&lt;code&gt;&#60;/span&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And it works.. but do you think it can be done in a smarter/faster way?&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.thetruetribe.com/2008/05/how-to-truncate-in-prototype.html" rel="nofollow"&gt;this guy&lt;/a&gt; does it in a very different way, but it doesn't work here :/&lt;/p&gt;

&lt;p&gt;Anyway, take care :)
Marc&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Ah crap, hadn't noticed that html tags was allowed here. They used to be forbidden with a big F! :P</p>

<p>Anyway , I wanted to know if you could limit other elements, like div, span and p with your script... and I've actually found a way to do it now with the prototype truncate string.</p>

<p>At the moment I'm just using:</p>

<p>Script:
<code>$('truncate').update($('truncate').innerHTML.truncate(10))</code></p>

<p>Content:
<code>&lt;/span</code></p>

<p>And it works.. but do you think it can be done in a smarter/faster way?</p>

<p><a href="http://www.thetruetribe.com/2008/05/how-to-truncate-in-prototype.html" rel="nofollow">this guy</a> does it in a very different way, but it doesn't work here :/</p>

<p>Anyway, take care :)
Marc</p>]]></content:encoded>
	</item>
</channel>
</rss>
