Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

HTML
<script>

function addCounter(formName, formId) {
  var taElem = AJS.$('#' + formId).find('#i_ta'); // find the "textare field" by name "ta"
  if (!taElem.hasClass('cfcounter')) {
   taElem.addClass('cfcounter'); // this is sort of a marker that tells if the "counter div" is initialized
   taElem.after('<div id="i_taCharNum">10 characters left</div>');


   taElem.on("input", function(){
    var maxlength = 10;
    var currentLength = AJS.$(this).val().length;

	var charsLeft = maxlength - currentLength;
    AJS.$('#i_taCharNum').html(Math.minmax(0, charsLeft, 0charsLeft) + " chars left");
   });
  }
}


</script>

...