Where should I put this JavaScript code ... the Drupal way? I´ve read that you can create a mini module to limit comments length.
I´ts cool, and it´s working, but I need to add to it some JS so it tells you how many characters you have left.

So I´ve found some easy thing to do (via Google):

Put this inside your head tag:

&lt;script language=”javascript”&gt;
function limit(what,chars,counter) {
if (what.value.length &gt; chars) {
what.value=what.value.substr(0,chars);
alert(‘You exceed to ‘ + chars + ‘chars!’);
}
counting = (chars – what.value.length);
c = document.getElementById(counter);
c.innerHTML = counting;
}
&lt;/script&gt;


And put this in your body:

&lt;label for=”text”&gt;&lt;strong&gt;Text&lt;/strong&gt;&lt;/label&gt; ¦ Chars left: &lt;span id=”count1″&gt;500&lt;/span&gt;&lt;/p&gt;
&lt;textarea name=”[1][3][t]” rows=”10″ cols=”50″ onkeyup=”limit(this,500,’count1′);” onkeydown=”limit(this,500,’count1′);” onblur=”limit(this,500,’count1′);” onfocus=”limit(this,500,’count1′);”&gt;&lt;/textarea&gt;


The thing is that I should add that inside the textarea of the comment body. As you can see, the code works, but how do I make it work the Drupal way?

I need only to limit comment length.

Thanks for your help!
Rosamunda
Why don't you simply use the Maxlength module that does exactly what you want already pre-packaged?

Otherwise, I would either write a custom module and use drupal_add_js() and hook_form_alter(), or use them in your template.php file without having to write a module.

If you're stumped, and want to know how to do it, why don't you download the Maxlength module and analyse how it is written to clarify the processes involved?