Control Form Completion

Description

There are times when you don't want the browser to fill out the form automatically.

We can use autocomplete attribute from form element to control this.

There are two allowed values for the autocomplete attribute: on and off.

The on value permits the browser to fill out the form and is the default value.

Example

The following code shows how you can do this, using the autocomplete attribute on the form element.


<!DOCTYPE HTML>
<html>
<body>
  <form autocomplete="off" 
        method="post" 
        action="http://example.com/form">
    <input name="fave" /> <input name="name" />
    <button>Submit Vote</button>
  </form><!--   w  ww .ja  v  a2s.c  o  m-->
</body>
</html>

Click to view the demo

You can be more specific by applying the autocomplete attribute to individual input elements, as shown in the following code.


<!DOCTYPE HTML>
<html>
<body>
  <form autocomplete="off" 
        method="post" 
        action="http://example.com/form">
    <input autocomplete="on" name="fave" /> 
    <input name="name" />
    <button>Submit Vote</button>
  </form><!--from   www.  j av  a 2  s.com-->
</body>
</html>

Click to view the demo

The autocomplete attribute on the form element sets the default policy for the input elements in the form.

You can override that policy for individual elements.

In the code above, the attribute on the form element disabled autocomplete, but the same attribute applied to the first input element switches it back on.

The second input element, to which the autocomplete attribute has not been applied, is subject to the form-wide policy.





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed