Question

how to fire event onkeydown after entering at least 3 characters? i will enter they in autocomplete, and after 3 characters calling function "autoload()" .

 <input type="text" id="autocomplete" onkeydown="autoLoad();" />

maybe I need some other event?

Was it helpful?

Solution

You just bind the keydown Event like you did then inside the function (autoLoad()) you check if the field has more then 3 chars, if it does then continue the script.

EDIT: I think this should work

function autoLoad() {
    if (document.getElementById('autocomplete').value.length >= 3) {
        // it has more then 3 chars
    }
}

OTHER TIPS

Pass the element into the autoLoad function ans check the length before your executable code.

... onkeydown="autoLoad(this)" ...


autoLoad = function ( element ){
    if(element.value.length > 3){
        doStuff();
    }
}

Example: http://jsfiddle.net/Chs3L/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top