“Auto complete” in input fields

“Auto complete” for input fields was already invented by Internet Explorer 5 and Netscape 6. Current browsers like Firefox, Chrome or Opera also provide this function.

For this the browser stores a history of earlier inputs whenever a form is submitted and shows this again as soon the user enters text. Generally the browsers checks the list by means of the input which entries in the history fit to the entered text and shows the found entries in a list below the input field where you can select them if needed:

autocomplete

Sometimes this function is quite disturbing – for example: when you want to display a list with places of findings (as in DokuWiki), which gets then covered by the “auto complete” list or which is displayed additionally to it.

For browsers which support this function you can also turn it off with the attribute “autocomplete” in INPUT elements:

Search: <input name="search" type="text" autocomplete="off" />

But this solution has some problems:

  • In (X)HTML “autocomplete” is not a valid attribute (it will be in HTML5)
  • If an alternative to “auto complete” is only practicable with JavaScript (as for example a direct search which shows findings below the input field during the input), the attribute should not be set if JavaScript can not be executed

Therefore it is a more reasonable solution to set this attribute with JavaScript. Where JavaScript can not be executed the regular behaviour of the browser is kept and the solution is also XHTML conform.

The HTML fragment in a modified form:

Search: <input d="seach" name="search" type="text" />

And the JavaScript part for it, which should be at the end of the document:

<script type="text/javascript">
if(document.getElementById("search") != null)
{
  if(typeof document.getElementById("search").autocomplete != "undefined")
  {
    document.getElementById("search").autocomplete = "off";
  }
}
</script>

But you should always consider that this changes the regular and expected behaviour of the browser – turning off “auto complete” for every input field in forms, just because you don’t like it personally, is not a good idea!

Weblinks

Leave a Comment

Your email address will not be published. Required fields are marked *