Friday 17 July 2015

Limit the No of characters entry in textarea control.


function LimitTextAreaContent() {
    $(".clstxtSummary").keydown(function (event) {
        if ($(this).val().trim().length > 500) {
            $(this).val($(this).val().trim().substring(0, 500));
        }
    });
    $(".clstxtJustification").keydown(function (event) {
        if ($(this).val().trim().length > 1000) {
            $(this).val($(this).val().trim().substring(0, 1000));
        }
    });
    $(".clstxtSummary").keyup(function (event) {
        if ($(this).val().trim().length > 500) {
            $(this).val($(this).val().trim().substring(0, 500));
        }
    });
    $(".clstxtJustification").keyup(function (event) {
        if ($(this).val().trim().length > 1000) {
            $(this).val($(this).val().trim().substring(0, 1000));
        }
    });
    $(".clstxtSummary").on('paste', function (event) {
        setTimeout(function () {
            var text = event.currentTarget.value;
            if (event.currentTarget.value.length > 500) {
                event.currentTarget.value = text.substring(0, 500);
            }
        }, 0);
    });
    $(".clstxtJustification").on('paste', function (event) {
        setTimeout(function () {
            var text = event.currentTarget.value;
            if (event.currentTarget.value.length > 1000) {
                event.currentTarget.value = text.substring(0, 1000);
            }
        }, 0);
    });
    (function ($) {
        $("textarea[id$='txtDelegateComments'], textarea[id$='txtComments'] , textarea[id$='txtResubComments'], textarea[id$='txtDCCComments'] ").bind("change keyup input", function () {
            if ($(this).val().trim().length > 250) {
                $(this).val($(this).val().trim().substring(0, 250));
            }
        });

    })(jQuery);
}

$(document).ready(function () {
    LimitTextAreaContent();
});

No comments:

Post a Comment