We are using the autocomplete jQuery plugin written by Jörn Zaefferer, and are trying to verify a valid option is entered.
The plugin has result() event which fires
I use a global data structure to keep track of the values that were found
var ac_sent = {};
the .result() event handler is called before the .change() event handler, so in .result( event, data, formatted ) I add the data to the structure:
ac_sent[ data ] = true;
then in the .change( event ) event handler I check to see if there is an item at ac_sent[ data ], and if there isn't any, I know that the word was not found:
$( "#textbox" ).change( function( event ) {
var data = event.target.value;
if ( !ac_sent[ data ] ) {
// result was not found in autocomplete, do something...
ac_sent[ data ] = true; // remember that we processed it
}
return false;
});