Turn red when entering bad text into combobox (autocomplete)

I wanted to turn the border of .dhx_combo_box red when the user is entering text, which is not found.

I tried to set up onKeyPressed event to do that and it works. However, autocompletion happens after the onKeyPressed event is triggered. So I turn the border red, but immediately thereafter the good result turns up - and I have no way of catching it.

What would be a good way to do this?

My list is loaded from xml, it is a filtered autocomplete.

I was using a function triggered onKeyPressed:

//first change styles to normal
if (!z.getSelectedText){
// change styles to indicate a problem
}
Thanks for the help!
Kate

Try to use the following approach

var t; z.attachEvent("onKeyPressed",function(){ if(t) window.clearTimeout(t); t = window.setTimeout(function(){ if(!z.getSelectedText()) z.DOMelem.style.borderColor = "red"; else z.DOMelem.style.borderColor = "#7F9DB9"; },100); })