Move this code into a function, or possibly a class, so that it can be shared, but customised to particular circumstances.
- No need to click OK to trigger a search.
- With more than MAX_USERS_PER_PAGE we don't display them. When there are fewer, we stop doing a server round-trip for the searches and reduce the timeout.
- If some users are already selected, and you change the search term, then those users stay selected, possibly being moved to a separate optgroup.
- If what you have typed uniquely identifies one user, that option is automatically selected.