// JavaScript Document

//Fernando B. 01/31/08

//Limits and counts the numbers of characters in a text area 

//Live and running example: http://www.cji.nova.edu/contactus.html

//call from textarea using onkeydown and onkeyup
//Example: <textarea id="myText" name="myText" cols="80" rows="8" onkeydown="textCounter(this.form.myText,this.form.remLen,2000);" onkeyup="textCounter(this.form.myText,this.form.remLen,2000);">
//Change 2000 to change the limit

//To show the count of limit, add this after the textarea:  <input type="text" name="remLen" size="4" maxlength="4" value="2000" readonly="readonly" class="select" /> <span class="smfont">characters left</span>
//If you changed the limit in the textarea above, change the value here as well. (Ex: 2000)


function textCounter(field, countfield, maxlimit) {

if (field.value.length > maxlimit) // if too long...trim it!

field.value = field.value.substring(0, maxlimit);

// otherwise, update 'characters left' counter

else 

countfield.value = maxlimit - field.value.length;

}