onkeyup or onkeypress only after X characters length

javascript, jquery

Solution

Use the `onkeyup` event:

let element = document.querySelector('your element');
element.onkeyup = function () {
    if (this.value.length > 10) {
        myFunction();
    }
}

You also use this in an attribute:

<textarea onkeyup="if (this.value.length > 10) myFunction();"></textarea>

EXAMPLE (for both)

Problem

There is anyway to call a js function only when we fill a number of characters characters on a textfield? from now im using onblur="myFunction();" but i wants to cal that function after we have some characters filled. Thank you!

Original source