Monday, May 12, 2008

Turning autocomplete off

Most modern browsers have a handy little feature which will check to see if you have filled in a text box before, and if so it will present you with a history of what you selected.

For the most part this is a very useful piece of functionality but for one caveat. The browser does not fire any kind of JavaScript event when this happens. Dynamic form validation based on user input thus becomes a (to use Dave Chappelle's word) "biatch".

Fortunately after digging around a little I found that there is a handy little attribute called "autocomplete" which you can set to "off" on the form element.

<form method="post" action="/registration/create" autocomplete="off">

This will keep those nasty little history drop downs from messing up your input validation.

No comments: