Javascript Autocomplete Text
Posted
by WPS
on Stack Overflow
See other posts from Stack Overflow
or by WPS
Published on 2010-06-01T08:40:13Z
Indexed on
2010/06/01
8:43 UTC
Read the original article
Hit count: 178
JavaScript
|autocomplete
Hi All, I need to implement an autocomplete text field using JavaScript and JSF. When the user types some character in a text field, I need to make an AJAX request and get the values based on the values entered.
I've an input text field, on "keyup" I'm triggering a function which submits the value to the server side.
var timeoutid = 0;
function intitiateTypeAhead(){
clearTimeout(timeoutid);
if (document.getElementById("inputText").value.length >= 2) {
timeoutid = setTimeout('clickButton', 500);
}
return false;
}
function clickButton(){
//submits the value to the server
}
<h:inputText id="inputText" onkeyup="intitiateTypeAhead()"></h:inputText>
This works properly, but certain times the request is made for each character entered by the user. I'm not sure if there is anything wrong with the implementation. Can someone please help me to fix this?
© Stack Overflow or respective owner