MAXLENGHT DE TEXTAREA

HTML

<textarea property="sMensaje" styleId="sMensaje" styleClass="text1" cols="100" rows="3"></textarea>

JAVASCRIPT

$(function(){
                maxLength = 140;
                $("#sMensaje").after("<div><span id='remainingLengthTempId'>" + maxLength + "</span> caracteres</div>");
                $("#sMensaje").bind("keyup change", function(){checkMaxLength(this.id,  maxLength); } )
            });

function checkMaxLength(textareaID, maxLength){
    currentLengthInTextarea = $("#" + textareaID).val().length;
    $(remainingLengthTempId).text(parseInt(maxLength) - parseInt(currentLengthInTextarea));
    if (currentLengthInTextarea > (maxLength)){
        $("#" + textareaID).val($("#" + textareaID).val().slice(0, maxLength));
        $(remainingLengthTempId).text(0);
    }
}

Comentarios

Entradas populares de este blog

Subir proyecto al repositorio existente en Bitbucket

Sonarqube : The component parameter is missing