CSC336 Web Technologies LAB03
CSC336 Web Technologies LAB03
HTML FORMS
Objective: To familiarize the students with the HTML forms and different input tags.
Activity Outcomes:
4. HTML Forms
Instructor Note:
As pre-lab activity, read Chapter 3 from the textbook “Web Design Playground: HTML & CSS the
Interactive Way 1st Edition, April 2019 by Paul McFedries”.
1. Useful Concepts
Introduction
HTML forms are used to pass data to a server. A form can contain input elements like text fields,
checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists,
textarea, fieldset, legend, and label elements. The <form> tag is used to create an HTML form.
<form>
input elements
</form>
The <form> tag
The <form arguments> ... </form> tag encloses form elements (and probably other elements as
well).The arguments to form tell what to do with the user input
17
action="url" (required)
Specifies where to send the data when the Submit button is clicked
method="get" (default)
Form data is sent as a URL with ?form_data info appended to the end
method="post"
Form data is sent in the body of the URL request
target="target" . Target tells where to open the page sent as a result of the request.
Input Tags
There are many input tags in the forms.
Text input
A text field:
<input type="text" name="textfield" value="with an initial value" /> A multi-line text field
<textarea name="textarea" cols="24" rows="2">Hello</textarea>
A password field:
<input type="password" name="textfield3" value="secret" />
Buttons
A submit button:
<input type="submit" name="Submit" value="Submit" /> A reset button:
<input type="reset" name="Submit2" value="Reset" /> A plain button:
<input type="button" name="Submit3" value="Push Me" />
Radio Buttons
Radio buttons:
<input type="radio" name="radiobutton" value="myValue1" /> male<br>
<input type="radio" name="radiobutton" value="myValue2” checked="checked" />female
18
Checkboxes
<input type="checkbox" name="checkbox" value="checkbox" checked="checked">
Drop-down menu
<select name="select">
<option value="red">red</option>
<option value="green">green</option>
<option value="BLUE">blue</option>
</select>
HTML5 is the current version of THML and still under development. HTML5 enhances HTML
form not only by providing new attributes to existing elements and but also provide new
elements which can be added to the HTML forms.
HTML5 attributes for existing elements Required: make an input field must to fill Pattern:
used to validate user’s input Readonly: makes an element read-only Disabled: is used to
make an input field disabled
Autocomplete: adds autocomplete functionality to input fields
19
<input type=”date” name=”dob”>
Color input field: displays color window to choose a color
<input type=”color” name=”favcolor”>
Number input field: makes an input field to accept only numeric values
<input type=”number”>
Activity 1:
3. Make a form with name, gender (use radio buttons) , password and submit
form option. Use text box for input fields and buttons for submit option
Solution:
<html>
<head>
<title>Get Identity</title>
</head>
<body>
<p>Name:
</p>
<p>Password:
</p>
<p>Gender:
20
<label><input type="radio" name="gender" value="m" />Male<label>
</p>
<p>:
</p>
</form>
</body>
</html>
Solution:
<!DOCTYPE html>
<html>
<style>
* {box-sizing: border-box}
input[type=text], input[type=password] {
width: 100%;
padding: 15px;
21
display: inline-block;
border: none;
background: #f1f1f1;
input[type=text]:focus, input[type=password]:focus {
background-color: #ddd;
outline: none;
hr {
margin-bottom: 25px;
button {
background-color: #04AA6D;
color: white;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
button:hover {
22
opacity:1;
.cancelbtn {
background-color: #f44336;
.cancelbtn, .signupbtn {
float: left;
width: 50%;
.container {
padding: 16px;
/* Clear floats */
.clearfix::after {
content: "";
clear: both;
display: table;
/* Change styles for cancel button and signup button on extra small screens */
23
@media screen and (max-width: 300px) {
.cancelbtn, .signupbtn {
width: 100%;
</style>
<body>
<div class="container">
<h1>Sign Up</h1>
<hr>
<label for="email"><b>Email</b></label>
<label for="psw"><b>Password</b></label>
<label>
</label>
<p>By creating an account you agree to our <a href="#" style="color:dodgerblue">Terms &
24
Privacy</a>.</p>
<div class="clearfix">
</div>
</div>
</form>
</body>
</html>
Lab Task 1
Write the HTML code for JOB application form of CIIT (find the complete job
application form fromCIIT web site)
25
Lab Task 2
Design the web template given below using Tables and forms concept in HTML. Moreover, add colors to
the fields and tables as mentioned below. Add links to connect face book, twitter, and terms &
conditions.
Grey
Light
Black Dark Blue blue
White
fields
Green
button
26