TextArea MaxLength Enforcement - jQuery

The following JavaScript function, which is dependent on jQuery, enforces the maxlength attribute for all textarea elements on the current page. This is necessary for Internet Explorer, since it seems to be the only browser which has the bug of not enforcing this attribute.

function enforceTextAreaMaxLen() {

    $('textarea[maxlength]').keyup(function () {

        var textbox = $(this);
        var maxlength = textbox.attr('maxlength');

        if (maxlength != undefined) {

            var x = parseInt(maxlength);
            var s = textbox.val();
            if (s != null && s.length > x) {
                textbox.val(s.substring(0, x));