Filter lookup field using client script

Filter lookup field using client script

Hi,

I used client scipt to filter a lookup field- the trigger is on detail page onload. It works, however sometimes when I start typing in that field the filter is removed and the whole list is shown. 

What can I do so that should not happen? 

Thanks