Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!doctype html>
<html>
    <head>
        <meta charset=utf-8>
        <title>textarea character limit</title>
    </head>
    <body>
        <textarea maxlength="50" id="text">This textarea has a limit of 50 characters.</textarea>
    </body>
</html>
 
function maxLength(el) {    
    if (!('maxLength' in el)) {
        var max = el.attributes.maxLength.value;
        el.onkeypress = function () {
            if (this.value.length >= max) return false;
        };
    }
}
maxLength(document.getElementById("text"));
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
creativitypro
0viewers