1 
  2 function limit_to(textarea, max_chars, chars_used_el, alert_truncate) {
  3     if (textarea.value.length > max_chars) {
  4         if(alert_truncate) {
  5             alert("The current text value exceeds the character limit; Any text after " + max_chars + " characters will be truncated");
  6         }
  7         textarea.value = textarea.value.substring(0, max_chars);
  8         textarea.focus();
  9     }
 10     document.getElementById(chars_used_el).innerHTML = textarea.value.length;
 11 }
 12