Textarea Character Limit

HTML:

<textarea maxlength="50" id="text">This textarea has a character limit of 50.</textarea>

Javascript:

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"));
Advertisements

Flask handle form array

To get the POST data on the Flask side you need to include the square brackets in the field name. You can retrieve all values of the list using MultiDict.getlist():

hello = request.form.getlist('hello[]')

You don’t have to use the [] convention at all, of course. Not appending the [] to the helloname will work perfectly fine, at which point you’d use request.form.getlist('hello') in Flask.