Well if you have to check the database, you can't do it completely on the client side. You either need to wait until the user submits the form to check the database as part of the post handling, or (and I DO NOT recommend this) post the form, or a subset of it, every time the user tabs out of the field to check if its value is unique.
Another apporach (which I'd also argue against) is to create a JavaScript array as the page is being constructed (perhaps via
JSP) populated with all the existing usernames. A few seconds of thought will reveal why this is not a recommended approach.
The conventional appraoch is to simply perform server-side checks upon form submission.
hth,
bear