My project has a requirement to provide an autocomplete function for a text box similar to the one recently used by Google. I need to get data every time I press a key, so I call the jQuery function when I press a key. The problem is that the autocomplete function is launched by clicking the mouse in the text field, and not by pressing a key. I will attach a code snippet to better understand the problem, which is as follows
$(document).keypress(function(){
lastKey = String.fromCharCode(window.event.keyCode);
alert('lastKey :: ' + lastKey);
var txtVal = document.frm.selectedTechParamName.value + lastKey;
alert('txtVal :: ' + txtVal);
$("#suggestTechParamName").autocomplete('/AEA-Authoring/TechnicianParameterAutocomplete?userAction=getTechParamsForSvcLvlDataID&txtVal=' + txtVal, {
matchContains: true,
minChars: 0,
cacheLength:0,
maxItemsToShow:10
});
});
Now, what happens when any key is pressed, the alerts work fine, but the second half of the function, i.e.
$("#suggestTechParamName").autocomplete('/AEA-Authoring/TechnicianParameterAutocomplete?userAction=getTechParamsForSvcLvlDataID&txtVal=' + txtVal, {
matchContains: true,
minChars: 0,
cacheLength:0,
maxItemsToShow:10
});
, . , , "cacheLength: 0", , , , - , .