Textarea Character limit function
Hi,
I found this solution for limiting characters inside a textarea for IE 10 and bellow:
<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"
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:
- var charLimit = 40;
- $('. textField').keyup(function(limitField, limitNum) {
if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum);}
- });
And removing
onkeyup
=
'
charLimit
(
this
,
40
);
' from the markup?
Thanks