Textarea Character limit function

Textarea Character limit function

Hi,

I found this solution for limiting characters inside a textarea for IE 10 and bellow:

  1. <input class='textField' type='text' maxlength="40" value='' onkeyup='charLimit(this, 40);'>

And following JavaScript function for IE 10 and bellow, which don't support maxlength="40"

  1. function charLimit(limitField, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum);} }

It works. However I wonder why it uses  onkeyup = ' charLimit ( this , 40 ); inside the markup?
Wouldn't be better to use something like:

  1. var charLimit = 40;
  2. $('. textField').keyup(function(limitField, limitNum) { 
  3. if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum);}
  4. });

And removing  onkeyup = ' charLimit ( this ,   40 ); from the markup?

Thanks