WE LAB 1 - 2k18 (Part 2) - 2
WE LAB 1 - 2k18 (Part 2) - 2
Laboratory # 01(Part:2)
10/2/2020
UET TAXILA
Engr. Sidra Shafi
HTML forms are used to pass data to a server. The <form> tag is used to create an HTML form
for user input.
The <form> element can contain one or more of the following form elements:
• <input>
• <textarea>
• <button>
• <select>
• <option>
• <fieldset>
• <label>
• <legend>
Form Attributes:
Program 1:
<form action="demo_form.asp">
First name: <input type="text" name="FirstName" value="Mickey"><br>
Last name: <input type="text" name="LastName" value="Mouse"><br>
<input type="submit" value="Submit">
</form>
<p>Click the "Submit" button and the form-data will be sent to a page on the server called
"demo_form.asp".</p>
</body>
</html>
Output:
1.
2.
Program 2:
Output:
1.
2.
i) Text Fields
<input type="text"> defines a one-line input field that a user can enter text into:
<form>
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" />
</form>
Note: The form itself is not visible. Also note that the default width of a text field is 20 characters.
Note: The characters in a password field are masked (shown as asterisks or circles).
<input type="radio"> defines a radio button. Radio buttons let a user select ONLY ONE of a
limited number of choices:
iv) Checkboxes
<input type="checkbox"> defines a checkbox. Checkboxes let a user select ZERO or MORE
options of a limited number of choices.
v) Submit Button
A submit button is used to send form data to a server. The data is sent to the page specified in the
form's action attribute. The file defined in the action attribute usually does something with the
received input:
If you type some characters in the text field above, and click the "Submit" button, the browser will
send your input to a page called "demo_form_action.asp". The page will show you the received
input.
Fieldset around form-data:
Code:
<!DOCTYPE html>
<html>
<body>
<form action="">
<fieldset>
<legend>Personal information:</legend>
Name: <input type="text" size="30"><br>
E-mail: <input type="text" size="30"><br>
Date of birth: <input type="text" size="10">
</fieldset>
</form>
</body>
</html>
Output:
The <label> element does not render as anything special for the user. However, it provides a
usability improvement for mouse users, because if the user clicks on the text within the <label>
element, it toggles the control.
The for attribute of the <label> tag should be equal to the id attribute of the related element to
bind them together.
Code:
<!DOCTYPE html>
<html>
<body>
<p>Click on one of the text labels to toggle the related control:</p>
<form action="demo_form.asp">
<label for="male">Male</label>
<input type="radio" name="sex" id="male" value="male"><br>
<label for="female">Female</label>
<input type="radio" name="sex" id="female" value="female"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Output:
Code:
<!DOCTYPE html>
<html>
<body>
<textarea rows="4" cols="50">
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development
technologies.
</textarea>
</body>
</html>
Output:
The <option> tags inside the <select> element define the available options in the list.
Note: The <select> element is a form control and can be used in a form to collect user input.
Note: The <option> tag can be used without any attributes, but you usually need the value
attribute, which indicates what is sent to the server.
Use the multiple attribute to allow the user to select more than one value:
Program 3:
Output:
Output:
Lab Task