Unit3 Notes
Unit3 Notes
Unit3 Notes
Example
Define a search field (like a site search, or Google search):
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<label for="gsearch">Search Google:</label>
<input type="search" id="gsearch" name="gsearch">
<input type="submit">
</form>
</body>
</html>
Output:
Definition and Usage
The <input type="search"> defines a text field for entering a search string.
Example
Show a date and time control (no timezone) :
Program:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<label for="birthdaytime">Birthday (date and time):</label>
<input type="submit">
</form>
</body>
</html>
Output:
The resulting value includes the year, month, day, and time.
Example
Define a field for entering a number (You can also set restrictions on what
numbers are accepted):
<label for="quantity">Quantity (between 1 and 5):</label>
<input type="number" id="quantity" name="quantity" min="1" max="5">
Program:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<input type="submit">
</form>
</body>
</html>
Output:
Example
Define a range control (like a slider control):
Program:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<input type="submit">
</form>
</body>
</html>
Output:
Definition and Usage
The <input type="range"> defines a control for entering a number whose exact value
is not important (like a slider control).
Default range is 0 to 100. However, you can set restrictions on what numbers
are accepted with the attributes below.
Example
Show a color picker (with a predefined red value):
Example:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<label for="favcolor">Select your favorite color:</label>
<input type="submit">
</form>
</body>
</html>
Output:
<form action="/action_page.php">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<input type="submit">
</form>
Example:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<label for="username">Username:</label>
<input type="submit">
</form>
</body>
</html>
Output:
Definition and Usage
The required attribute is a boolean attribute.
When present, it specifies that an input field must be filled out before submitting
the form.
Note: The required attribute works with the following input types: text, search,
url, tel, email, password, date pickers, number, checkbox, radio, and file.
Attribute Description
HTML
<input> placeholder Attribute
❮ HTML <input> tag
Example
A telephone input field with a placeholder text:
<form action="/action_page.php">
<label for="phone">Enter a phone number:</label><br><br>
<input type="tel" id="phone" name="phone" placeholder="123-45-678"
pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}"><br><br>
<small>Format: 123-45-678</small><br><br>
<input type="submit">
</form>
Ex:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<small>Format: 123-45-678</small><br><br>
<input type="submit">
</form>
</body>
</html>
o/p:
Definition and Usage
The placeholder attribute specifies a short hint that describes the expected
value of an input field (e.g. a sample value or a short description of the
expected format).
The short hint is displayed in the input field before the user enters a value.
Note: The placeholder attribute works with the following input types: text,
search, url, tel, email, and password.
Example
<input type="text" autocomplete="off">
You can also turn off autocomplete for the whole form:
Example
<form autocomplete="off">
Ex:
<!DOCTYPE html>
<html>
<body>
<h2>Autocomplete on/off</h2>
<form action="/action_page.php">
First name: <input type="text" name="fname" autocomplete="off"><br>
Last name: <input type="text" name="lname" autocomplete="on"><br>
<input type="submit">
</form>
<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 last name field, but "off" for
the first name field.</p>
</body>
</html>
o/p:
Restricting values
HTML <input type="number">
❮ HTML <input> type attribute
Example
Define a field for entering a number (You can also set restrictions on what
numbers are accepted):