HTML Forms are required when you want to collect some data from the site visitor. For example, during user registration, you would like to collect information such as name, email address, credit card, etc.
There are various form elements available like text fields, text area fields, drop-down menus, radio buttons, checkboxes, etc.
The HTML <form> tag is used to create an HTML form and it has the following syntax –
1. By using Notepad, type the following text:
<!DOCTYPE html>
<html>
<body>
<h2>LAB-06 HTML Forms</h2>
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value=""><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value=" "><br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "submit" button, the form-data will be sent to a page called "/action_page.php".</p>
</body>
</html>
1. Explain about the HTML code above.
2. Write a HTML code to display the output as show as Figure Q2 on the webpage.
<input> is an attribute. Type=”” specify the value of data. For example, type=”text” displays a single-line text input field. name=”” is the identifier that is sent to the server when the form is submitted.id=”” is a unique identifier for the browser for javascript and such.
For example, id="fname” is for last name. value=”” is used to display a temporary data. Label is used to name the input itself.
<h2>LAB-06-Q2 HTML Forms</h2>
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="">
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname" value=" "><br><br>
<label for="lname">ID:</label>
<input type="number" id="number" value=" ">
<label for="lname">Age:</label>
<input type="number" id="age" value=" "><br><br>
<input type="submit" value="Submit">