Domanda

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?

È stato utile?

Soluzione

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
    }
}

Altri suggerimenti

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/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top