HTML Forms
HTML Forms
An HTML form is used to collect user input. The user input is most often sent
to a server for processing.
For example during user registration you would like to collect information such
as name, email address, credit card, etc.
The <form> tag is used to create a form for user input in Html.
Syntax: <form>
.
form elements
.
</form>
It is a container for different types of input elements
HTML Forms
The HTML <input> element is the most used form
element.
Attribute Description
Type Indicates the type of input control and for text
input control it will be set to text.
Ifthe name attribute is omitted, the value of that input field will
not be sent at all.
Example:
This example will not submit the value of the "First name" input
field:
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" value="John"><br><br>
<input type="submit" value="Submit">
</form>
Example:
<form>
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="pwd">Password:</label><br>
<input type="password" id="pwd" name="pwd">
</form>
<form>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<input type="radio" id="other" name="gender" value="other">
<label for="other">Other</label>
</form>
Attributes:
Value: The value that will be used if the radio box is selected.
Checked: Set to checked if you want to select it by default.
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
Example:
<form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label>
</form>
Attributes:
Value : The value that will be used if the checkbox is selected.
Checked: Set to checked if you want to select it by default.
Checkboxes-input control
The <select> element defines a drop-down list.
Example:
<form>
<label for="Programming Language">Choose a Programming Language:</label>
<select id="program" name="program"> <!-- size="3", multiple="3", selected,
label="Vol"-->
<option value="volvo">C</option>
<option value="saab">C++</option>
<option value="fiat">Java</option>
<option value="audi">Python</option>
</select>
</form>
Attributes:
The <input type="submit"> defines a button for submitting the form data
to a form-handler.
The form-handler is typically a file on the server with a script for processing
input data.
Example:
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value=“Rohit"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value=“Sharma"><br><br>
<input type="submit" value="Submit">
</form>
Usually, the form data is sent to a file on the server when the user
clicks on the submit button.
Reset Button
The <button> element defines a clickable button:
Example:
<!DOCTYPE html>
<html>
<body>
</body>
</html>