25th TUTORIAL ON HTML FORMS PATR 4TH FORMS ATTRIBUTES
HTML Input Attributes
This chapter describes the different attributes for the HTML <input>
element.
The value Attribute
The input value
attribute specifies an initial value for an input field:
Example
Input fields with initial (default) values:
<!DOCTYPE html>
<html>
<body>
<h1>The input value attribute</h1>
<p>The value attribute specifies an initial value for an input field:</p>
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="HAPPY"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="RAWAT"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
OUTPUT
The input value attribute
The value attribute specifies an initial value for an input field:
The readonly Attribute
Example
The input readonly attribute
The disabled Attribute
Example
The input disabled attribute
The size Attribute
Example
The input size attribute
The maxlength Attribute
Example
The input maxlength attribute
The multiple Attribute
Example
The input multiple attributes
To select multiple files, hold down the CTRL or SHIFT key while selecting.
The pattern Attribute
Example
The input pattern attribute
Note: The pattern attribute of the input tag is not supported in Safari 10 (or earlier).
The placeholder Attribute
Example
The input placeholder attribute
The required Attribute
The input required attribute
Note: The required attribute of the input tag is not supported in Safari prior version 10.1.
The step Attribute
Example
The input step attribute
The autofocus Attribute
Example
The input autofocus attribute
The height and width Attributes
The input height
and width
attributes specify the height and width of an <input type="image">
element.
The input height
and width
attributes specify the height and width of an <input type="image">
element.
The list Attribute
The input list
attribute refers to a <datalist>
element that contains pre-defined options for an <input> element.
The input list
attribute refers to a <datalist>
element that contains pre-defined options for an <input> element.
Example
An <input> element with pre-defined values in a <datalist>:
<!DOCTYPE html>
<html>
<body>
<h1>The input list attribute</h1>
<p>The list attribute refers to a datalist element that contains pre-defined options for an input element.</p>
<form action="/action_page.php">
<input list="browsers" name="browser">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
<input type="submit" value="Submit">
</form>
<p><b>Note:</b> The datalist tag is not supported in Safari 12.0 (or earlier).</p>
</body>
</html>
OUTPUT
An <input> element with pre-defined values in a <datalist>:
<!DOCTYPE html>
<html>
<body>
<h1>The input list attribute</h1>
<p>The list attribute refers to a datalist element that contains pre-defined options for an input element.</p>
<form action="/action_page.php">
<input list="browsers" name="browser">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
<input type="submit" value="Submit">
</form>
<p><b>Note:</b> The datalist tag is not supported in Safari 12.0 (or earlier).</p>
</body>
</html>
OUTPUT
The input list attribute
The list attribute refers to a datalist element that contains pre-defined options for an input element.
Note: The datalist tag is not supported in Safari 12.0 (or earlier).
The list attribute refers to a datalist element that contains pre-defined options for an input element.
Note: The datalist tag is not supported in Safari 12.0 (or earlier).
The autocomplete Attribute
The input autocomplete
attribute specifies whether a form or an input field should have autocomplete on or off.
Autocomplete allows the browser to predict the value. When a user starts to type in a field, the browser should display options to fill in the field, based on earlier typed values.
The autocomplete
attribute works with <form>
and the following <input>
types: text, search, url, tel, email, password, datepickers, range, and color.
<!DOCTYPE html>
<html>
<body>
<h1>The autocomplete attribute</h1>
<p>The autocomplete attribute specifies whether or not an input field should have autocomplete enabled.</p>
<p>Fill in and submit the form, then reload the page to see how autocomplete works.</p>
<p>Notice that autocomplete is "on" for the form, but "off" for the e-mail field!</p>
<form action="/action_page.php" autocomplete="on">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" autocomplete="off"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
OUTPUT
The input autocomplete
attribute specifies whether a form or an input field should have autocomplete on or off.
Autocomplete allows the browser to predict the value. When a user starts to type in a field, the browser should display options to fill in the field, based on earlier typed values.
The autocomplete
attribute works with <form>
and the following <input>
types: text, search, url, tel, email, password, datepickers, range, and color.
<!DOCTYPE html>
<html>
<body>
<h1>The autocomplete attribute</h1>
<p>The autocomplete attribute specifies whether or not an input field should have autocomplete enabled.</p>
<p>Fill in and submit the form, then reload the page to see how autocomplete works.</p>
<p>Notice that autocomplete is "on" for the form, but "off" for the e-mail field!</p>
<form action="/action_page.php" autocomplete="on">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" autocomplete="off"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
OUTPUT
The autocomplete attribute
The autocomplete attribute specifies whether or not an input field should have autocomplete enabled.
Fill in and submit the form, then reload the page to see how autocomplete works.
Notice that autocomplete is "on" for the form, but "off" for the e-mail field!
The autocomplete attribute specifies whether or not an input field should have autocomplete enabled.
Fill in and submit the form, then reload the page to see how autocomplete works.
Notice that autocomplete is "on" for the form, but "off" for the e-mail field!
Comments
Post a Comment