treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Turn Off Autocomplete for Input

Last updated on:

Just use the autocomplete attribute:

<input name="q" type="text" autocomplete="off"/>

This would be useful when a text input is one-off and unique. Like a CAPTCHA input, one-time use codes, or for when you have built your own auto-suggest/auto-complete feature and need to turn off the browser default.

View Comments

Comments

  1. To make your web application iPhone and iPad friendly, you can also control whether or not automatic correction or capitalization is used in your form’s input fields. This can come in handy for username fields. Do so by implementing code along the following lines:

    To turn off autocorrect:


    <input type="text" name="some_name" autocorrect="off"></input>

    To turn off autocapitalize:


    <input type="text" name="some_name" autocapitalize="off"></input>

  2. Permalink to comment#

    autocomplete=”off” is not valid markup with XHTML Transitional, which is a common DOCTYPE. Use this to keep a vaild markup

    if (document.getElementsByTagName) {

    var inputElements = document.getElementsByTagName(“input”);

    for (i=0; inputElements[i]; i++) {

    if (inputElements[i].className && (inputElements[i].className.indexOf(“disableAutoComplete”) != -1)) {

    inputElements[i].setAttribute(“autocomplete”,”off”);

    }

    }

    }

  3. a dev
    Permalink to comment#

    thx a lot u solved my problem :)

  4. Permalink to comment#

    Thank You…The Javascripts works for me :)

  5. asd
    Permalink to comment#

    asfsda

  6. Is there anyway to style the autocomplete? (without js)
    I have seen:
    #inputId:-webkit-autofill {
    background-color: white !important;
    } (bug)

    But it is not working and only for webkit browsers. I have a large font-size for “placeholder=”blabla” and need autocomplete. The autocomplete with this font size is look horrific…
    So:
    .search_field{font-size: 1.5em;} (input)
    .search_field:-webkit-autofill{font-size: .9em;}(autofill)

    :)

  7. Paresh
    Permalink to comment#

    The autofill feature on iOS not always work based on the site being surfed. I have web application when browsed on iPad the autofilll does not work. Is there any trick to enable it? Please advise

  8. Vivek Doshi
    Permalink to comment#

    There is a small issue using, when the page is validated with w3c validator it shows error “there is no attribute “autocomplete”"

  9. Martin Delille
    Permalink to comment#

    I ask stackexchange.com to add this feature providing a link to your blog article: http://meta.stackoverflow.com/q/148009/195437

  10. kunal
    Permalink to comment#

    Add form Tag autocomplete=”off” you don’t need add individual input tag for auto complete off

  11. Cormorand
    Permalink to comment#

    Probably not a good idea if your visitors use Chrome, kunal.

    See http://stackoverflow.com/questions/7973462/chrome-ugly-message-when-autofill-is-disabled.

Leave a Comment

Use markdown or basic HTML and be nice.