Web Programming Lab Manual BCSE203E
Web Programming Lab Manual BCSE203E
VIT
Vellore Institute of Technology
(Deened to be Uvetsily uudet section 3 of UGC Act, 1956)
LAB MANUAL
Course
Assessment Assessment
Modules to Outcome
[Link] Component Weightage Component
be covered (CO)
Name Type
Mapping
1. Assessment 1 Module 1, 2, 3 10 CO1
2. Assessment 2 Module 4,5 10 CO2
3. Assessment 3 Module 6,7 10 CO3
Internal
4. Mini Project All 20 CO4 Assessment
5. Quiz Module 1, 2, 3 10 CO1
Total -100
NETBEANS
[Link]
installers/16/[Link]
ECLIPSE
[Link]
wnloads/release/neon /2/eclipse-java-neon-2-win32-x86_64.zip
EDITORS
NOTEPAD++
[Link]
ATOM
[Link]
ONLINE EDITORS
[Link]
[Link]
[Link]
ASSIGNMENTS
7
Implement Event Handlers to design a 30
dynamic web page
Apply Constructor and hooks concept by 34
using React JS
Design a simple search filter functionality to
display a filtered list based on the search query 37
entered by the user using React JS
10 Apply props validation in React component 39
11
Implement routing concept to simplify the 43
navigations in web page design
12 Additional Exercises 48
Problem Statement
Create a web page Using Paragraphs, Text, Lists, Images and Tables.
Concept to be Applied
Write a code to display the webpage with following HTML elements
Paragraph
Heading
Bold & Strong Tag
Label
Textbox
Small
Italic
Strike
Images
Tables
Procedure/Steps
<html>
<head>
<title>Text Alignment</title>
</head>
<body>
<br><br>
<h2 align="center" style="color:darkgreen"><b>USING THE INTERNET CONNECTION
WIZARD</b>
</h2>
<p align="justify" style="font-family:arial;font-size:16px">
Connecting to the Internet is quick and easy using the Internet Connection wizard. The Internet
Connection wizard helps you set up your computer to communicate with the Internet,helps
you sign up for an account with an Internet Service provider,and sets up the Internet software
you need to use your [Link] you've completed the wizard,you are ready to explore the
Internet.
</p>
<p align="justify" style="font-family:arial;font-size:16px">
To start the wizard for the first time,double-click The Internet icon on your desktop. If you need
to start the wizard again at a later time,click the Start menu, point to programs, point to
Output:
Problem Statement
You volunteer at a local food bank called ABC Food Bank that collects community food
donations and provides food and other services to those in need. The company has asked you
to create a responsive website using semantics html.
Concept to be Applied
Sematic html tags such as navigations, section, article and aside and non-semantic html tags
such as div, span
Procedure/Steps
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Semantics html ABC food bank</title>
</head>
<body>
<header>
<hgroup>
<img src="food [Link]" alt="food bank" width="100" height="100" align="left"/>
<h1 align="center" style="color:darkgreen"><strong>ABC FOOD
BANK</strong></h1>
<h2 align="right" style="color:red"><em><i>-Nourishing Communities: Briding the
food gap </em></i></h2>
</hgroup>
</header>
<nav>
<a href="/home/">
Home
</a> |
<a href="/about-us/">
About Us
</a> |
<a href="/Volunteer/">
Volunteer
</a> |
<a href="/Contact us/">
Output
Problem Statement
Include CSS style for the above food bank problem as mentioned in task 2 and apply with
different types of CSS
Concept to be Applied
Write a script to display the webpage with following HTML elements
Internal CSS, Internal CSS and External CSS
Div tag
Style
Procedure/Steps
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Semantics html ABC food bank</title>
<style>
aside {
width: 75%;
padding-left: 15px;
margin-left: 30px;
float: right;
font-style: italic;
background-color: lightgray;
}
main {
width: 75%;
padding-left: 15px;
margin-left: 30px;
float: right;
font-style: italic;
background-color: lightgray;
}
section article {
float: left;
margin: 0 1.5%;
width: 40%;
}
BCSE203E – Web Programming – Lab Manual Page 7 of 54
footer {
position:fixed;
bottom:0;
left:0;
width:100%;
height: 50px;
background-color: #D0DAEE;
}
</style>
</head>
<body>
<header style="background-color:#33475b">
<hgroup>
<img src="food [Link]" alt="food bank" width="100" height="100" align="left"/>
<h1 align="center" style="color:white"><strong>ABC FOOD BANK</strong></h1>
<h2 align="right" style="color:red"><em><i>-Nourishing Communities: Briding the
food gap </em></i></h2>
</hgroup>
</header>
<nav>
<a href="/home/">
Home
</a> |
<a href="/about-us/">
About Us
</a> |
<a href="/Volunteer/">
Volunteer
</a> |
<a href="/Contact us/">
Contact Us
</a>
</nav>
<div>
<article>
<header style="background-color:#33475b">
<h1>Food Banking #1</h1>
</header>
<p>
</figure>
</aside>
</div>
<footer>
<p>© [Link]</p>
</footer>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="[Link]">
</head>
[Link]
aside {
width: 75%;
padding-left: 15px;
margin-left: 30px;
float: right;
font-style: italic;
background-color: lightgray;
}
main {
width: 75%;
padding-left: 15px;
margin-left: 30px;
float: right;
font-style: italic;
background-color: lightgray;
BCSE203E – Web Programming – Lab Manual Page 10 of 54
}
section article {
float: left;
margin: 0 1.5%;
width: 40%;
}
footer {
position:fixed;
bottom:0;
left:0;
width:100%;
height: 50px;
background-color: #D0DAEE;
}
Output
Problem Statement
Create a web application for ABC Food Bank using HTML and CSS properties, apply with
different styles
Concept to be Applied
Procedure/Steps
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ABC Food Bank</title>
<style>
/* Global styles */ body {
font-family: 'Arial', sans-serif; margin: 0;
padding: 0;
background-color: #f5f5f5; color: #333;
}
/* Navbar styles */
.navbar {
background-color: #333; overflow: hidden;
}
.navbar a {
/* Banner styles */
.banner {
text-align: center;
/* Transactions styles */
.transactions {
max-width: 600px; margin: 20px auto; padding: 20px; background-color: white;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.transactions table, .transactions table th, .transactions table td { border: 1px solid #ddd;
padding: 8px; text-align: left;
}
/* Footer styles */
.footer {
/* Dropdown Profile */
.dropdown {
float: left; overflow: hidden;
}
.dropdown .dropbtn { font-size: 16px; border: none; outline: none; color: white; padding: 14px
16px;
background-color: inherit; cursor: pointer;
}
/* Form Styles */
/* Testimonials Styles */
.testimonials {
max-width: 600px; margin: 20px auto; padding: 20px; background-color: white;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<!-- Navigation Bar -->
<div class="navbar">
<a href="#home">Home</a>
<a href="#services">Services</a>
<a href="#contact">Contact</a>
<!-- Profile Dropdown -->
<div class="dropdown">
<button class="dropbtn">Joe</button>
<div class="dropdown-content">
<a href="#">Profile</a>
<a href="#">Settings</a>
<a href="#">Logout</a>
</div>
</div>
</div>
Job2:
Write a script with a function solve Quadratic() taking three parameters a, b and c. Allow the
function to find the real roots of the quadratic equation. Use appropriate forms to capture the
values from the user. Use Math object to find the square root of a number.
Concept to be Applied
Basics of JavaScript- alert, prompt , for loop, if- else, function, on-submit
Job1
<html>
<head><title> Squares and Cubes </title></head>
<script>
[Link]('<p><b>SQUARES AND CUBES FROM 0 TO 10</b></p>');
[Link]('<table border="2" cellspacing="2">');
[Link]('<th> Number </th> <th> Square </th> <th> Cube </th>');
for(var i=1;i<=10;i++)
[Link]("<tr><td>"+ i +"</td><td>"+ i*i + "</td><td>"+ i*i*i +"</td></tr>");
[Link]("</table>");
</script>
</html>
Job 2
<html xmlns="[Link]
<head>
<title>[Link] Code</title>
<script type="text/javascript">
function solveQuadratic()
{
a=[Link];
b=[Link];
c=[Link];
var det=b*b-4*a*c;
if(det<0)
alert("Sorry!! Computing Roots is impossible");
else
{
var x1=(-b+[Link](det))/(2*a);
var x2=(-[Link](det))/(2*a);
alert("The roots of are "+x1+" and "+x2); }
}
</script>
</head>
<body>
<form name="form1" onSubmit="return solveQuadratic();" "method="get">
<h1>Solving Quadratic Equation</h1>
<h3> Enter Parameters:</h3><br>
Procedures:
Job1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Volunteer Registration Form</title>
<link rel="stylesheet" href="[Link]" />
<script>
function validateForm() {
var firstName = [Link]('firstName').value;
var lastName = [Link]('lastName').value;
var email = [Link]('email').value;
var password = [Link]('password').value;
var confirmPassword = [Link]('confirmPassword').value;
// Simple validation for demonstration purposes
if (firstName === '' || lastName === '' || email === '' || password === '' ||
confirmPassword === '') {
alert('All fields must be filled out');
return false;
}
if (password !== confirmPassword) {
alert('Passwords do not match');
return false;
}
// Additional validation logic can be added based on requirements
return true; // Form is valid
}
</script>
</head>
<body>
<div class="container">
<h2>ABC Food Bank Volunteer Registration Form</h2>
Job2:
<html><head>
<title>Demo of JavaScript listbox validation in a form</title>
<link rel="stylesheet" href="[Link]" />
<script type="text/javascript">
function data_check()
{
var firstName = [Link]('uname').value;
var email = [Link]('email').value;
if (firstName === '' || email === '') {
alert('All fields must be filled out');
return false;
}
var str=[Link]("l1").value;
if([Link] <=0){
alert("Please select one option ");
}else{
[Link]['drop_list'].submit();// working
const male = [Link]('.male');
const female = [Link]('.female');
BCSE203E – Web Programming – Lab Manual Page 24 of 54
if(![Link] && ![Link]){
alert('Please choose your Gender: Male or Female ')
}else{
alert('Form submitted!')
}
}
var checkbox = [Link]("accept");
if (![Link]){
[Link]("error").innerHTML = "You must accept the terms and conditions
by checking the Checkbox";
return false;
}
}
</script>
</head>
<body>
<form name="drop_list" method="post" id='f1'class="form" style="background-
color:#E6E6FA">
<div class="form-control">
<label for="uname">Username</label>
<input type="text" id="uname" placeholder="Enter username" />
<small>Error message</small>
</div>
<div class="form-control">
<label for="email">Email</label>
<input type="text" id="email" placeholder="Enter email" />
<small>Error message</small>
</div>
<div class="formdivider">
<label for="class"><b>Gender:</b></label><br>
<input type="radio" class="male" name="gender" value="Male"> Male <br>
<input type="radio" class="female" name="gender" value="Female"> Female <br>
</div><br>
<div class=""form-control">
<label for="class"><b>Date of Birth:</b></label><br>
<input type="date"name="dt">
</div><br>
<div class="form-control">
<fieldset>
<legend>Address:</legend>
[Link]
@import url('[Link]
:root {
--success-color: #2ecc71;
--error-color: #e74c3c;
}
*{
box-sizing: border-box;
}
body {
background: linear-gradient(to bottom, rgba(0,0,0,.5), rgba(0,0,0,.5)), url("./[Link]");
background-position: center;
font-family: 'Open Sans', sans-serif;
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
}
.container {
BCSE203E – Web Programming – Lab Manual Page 27 of 54
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
width: 400px;
}
h2 {
text-align: center;
margin: 0 0 20px;
}
.form {
padding: 30px 40px;
}
.form-control {
margin-bottom: 10px;
padding-bottom: 20px;
position: relative;
}
.form-control label {
color: #777;
display: block;
margin-bottom: 5px;
}
.form-control input {
border: 2px solid #f0f0f0;
border-radius: 4px;
display: block;
width: 100%;
padding: 10px;
font-size: 14px;
}
.form-control input:focus {
outline: 0;
border-color: #777;
}
.[Link] input {
border-color: var(--success-color);
}
.[Link] input {
border-color: var(--error-color);
}
Problem:
Implement the following dynamic interactions on a web page using HTML and JavaScript:
i. Create a 'click' event handler to toggle the background color of area 'A' between
'silver' and 'gold'.
ii. Implement a 'mouseover' event handler for area 'B' that cycles its background color
through "blue", "lime", "red", "yellow", "green", and back to "blue" with each mouse
movement.
iii. Use 'mouseenter' and 'mouseleave' event handlers for area 'C' to change its
background color to "red" when the mouse enters and to "green" when it leaves.
iv. Apply 'dblclick' event handlers for area 'D’ to modify its background color to
“pink”
Procedures:
HTML Structure:
JavaScript Functions:
registerAllEvents(): This function is called when the body of the HTML document is
loaded. It registers various event listeners for the specified div elements.
handleDivA(evt): Toggles the background color of div A between silver and gold on a
'click' event.
handleDivB(evt): Changes the background color of div B in a cyclic pattern ("blue" ->
"lime" -> "red" -> "yellow" -> "green" -> "blue") on a 'mousemove' event.
handleDivC_1(evt): Changes the background color of div C to red on a 'mouseenter'
event.
handleDivC_2(evt): Changes the background color of div C to green on a 'mouseleave'
event.
handleDivD_1(evt): Changes the background color of div D to pink on a 'dblclick'
event.
CSS Styling:
The CSS styles define a grid layout with two rows and two columns, with a small gap
between the cells.
Body Section:
The <body> tag has an onload attribute set to registerAllEvents(), ensuring that the
JavaScript functions are executed when the body is loaded.
Inside the body, there is a <div> element with the class "container" containing four
child div elements (divA, divB, divC, and divD), each representing a cell in the grid.
Event Listeners:
Event Handling:
Program:
<!DOCTYPE html>
<html>
<head>
<script>
function registerAllEvents() {
// register different event types
[Link]("divA").addEventListener('click', handleDivA);
[Link]("divB").addEventListener('mousemove', handleDivB);
// two event handler for the same element
[Link]("divC").addEventListener('mouseenter', handleDivC_1);
[Link]("divC").addEventListener('mouseleave', handleDivC_2);
[Link]("divD").addEventListener('dblclick', handleDivD_1);
}
function handleDivA(evt) {
// toggle between silver and gold
const elem = [Link];
if ([Link] !== 'silver') {
[Link]("style", "background-color: silver");
} else {
[Link]("style", "background-color: gold");
BCSE203E – Web Programming – Lab Manual Page 31 of 54
}
}
function handleDivB(evt) {
// rotate in a palette of colors
const elem = [Link];
switch ([Link]) {
case "blue":
[Link]("style", "background-color: lime");
break;
case "lime":
[Link]("style", "background-color: red");
break;
case "red":
[Link]("style", "background-color: yellow");
break;
case "yellow":
[Link]("style", "background-color: green");
break;
default:
[Link]("style", "background-color: blue");
break;
}
}
function handleDivC_1(evt) {
// switch to a certain color
[Link]("style", "background-color: red");
}
function handleDivC_2(evt) {
// switch to a certain color
[Link]("style", "background-color: green");
}
function handleDivD_1(evt) {
// switch to a certain color
[Link]("style", "background-color: pink");
}
</script>
<style>
.container {
display: grid;
Output:
Problem:
Create a simple counter that increments dynamically on-screen as the user clicks on the
respective button by applying functional component state with hooks. Also, design a
decrement counter by utilizing the concepts of class component life cycle and constructor to
build a react application.
Procedures:
Functional component (Increment Counter)
1. Create a functional component named Counter
2. Utilize the useState hook for managing the state of the counter.
3. Display the current count on the screen.
4. Implement two buttons, enabling users to increment and decrement the count.
[Link]
import React, { useState, useEffect } from 'react';
function Counter() {
const [count, setCount] = useState(0);
const incrementCount = () => setCount(count + 1);
useEffect(() => {
[Link] = `You clicked ${count} times`
});
return (
<div>
<p>You clicked {count} times</p>
<button onClick={incrementCount}>Increment counter </button>
</div>
)
}
export default Counter;
[Link]
import Counter from './Counter'
function App() {
return (
<div classname="App">
<Counter/>
Output:
Class Component
1. Create a class component named Counter.
2. In the constructor, initialize the state to manage the counter.
3. Display the current count on the screen.
4. Implement two buttons for incrementing and decrementing the count.
5. Incorporate the componentDidMount and componentDidUpdate life cycle methods to
log messages in the console, indicating when the component has mounted and when it
has updated.
[Link]
import React from 'react';
class Counter extends [Link] {
constructor(count) {
super(count);
[Link] = { count: 0 };
[Link] = [Link](this);
[Link] = [Link](this);
}
incrementCount() {
[Link]({ count: [Link] + 1 });
}
decrementCount() {
[Link]({ count: [Link] - 1 });
}
componentDidMount() {
BCSE203E – Web Programming – Lab Manual Page 35 of 54
[Link] = `You clicked ${[Link]} times`;
}
componentDidUpdate() {
[Link] = `You clicked ${[Link]} times`;
}
render() {
return (
<div>
<p>You clicked {[Link]} times</p>
<button onClick={[Link]}>Increment</button>
<button onClick={[Link]}>Decrement</button>
</div>
);
}
}
[Link]
import Counter from './Counter'
function App() {
return (
<div classname="App">
<Counter/>
</div>
);}
Output:
Problem:
Implement react concepts to design a simple search filter functionality to display a filtered list
based on the search query entered by the user.
Procedures:
[Link]
import React, { useState } from "react";
function Search() {
const list = [
"Banana",
"Apple",
"Orange",
"Mango",
"Pineapple",
"Watermelon"
];
const [filterList, setFilterList] = useState(list);
const handleSearch = (event) => {
if ([Link] === "") {
setFilterList(list);
return;
}
const filteredValues = [Link](
(item) =>
[Link]().indexOf([Link]()) !== -1
BCSE203E – Web Programming – Lab Manual Page 37 of 54
);
setFilterList(filteredValues);
};
return (
<div className="app">
<div>
Search: <input name="query" type="text" onChange={handleSearch} />
</div>
{filterList &&
[Link]((item, index) => (
<div key={index}>{item}</div> //Display each item
))}
</div>
);
}
export default Search;
[Link]
import Search from './Search'
function App() {
return (
<div classname="App">
<Search/>
</div>
);}
export default App;
Output:
Problem:
Apply props validation using PropTypes to ensure that all the required props are present.
Validate the following data types for the respective props:
a. userName (string): Ensure it is a string.
b. userAge (number): Ensure it is a number.
c. userSkills (array): Ensure it is an array.
d. isActive (boolean): Ensure it is a boolean.
e. updateUser (function): Ensure it is a function.
Procedures:
[Link]
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class User extends [Link] {
render() {
return (
<div>
<h1>ReactJS Props validation example</h1>
<table>
<tr>
<th>User details</th>
<th>Value</th>
</tr>
<tr>
<td>User name</td>
<td>{[Link]}</td>
</tr>
<tr>
<td>User age</td>
<td>{[Link]}</td>
</tr>
<tr>
<td>User Skills</td>
<td>{[Link]}</td>
</tr>
<tr>
<td>User active</td>
<td>{[Link] ? "yes" : "no"}</td>
</tr>
[Link] = {
propArray: [Link],
propBool: [Link],
propFunc: [Link],
propNumber: [Link],
propString: [Link],
}
[Link] = {
propArray: ["C","C++","JAVA"],
propBool: true,
propFunc: function(x){return x},
propNumber: 25,
propString: "John",
}
export default User;
[Link]
</div>
);}
Problem:
Create a React application with four distinct web pages: Home, About, Product and Contact.
Utilize React Router to establish the necessary routes for navigation between these pages.
Additionally, implement a navigation bar that provides users with the ability to switch
effortlessly between the Home, About, Product and Contact pages.
Procedures:
1. Install router by using the following command.
npm install react-router-dom@6 –save
2. Create four components [Link], [Link], [Link] and [Link] along with
[Link], which is already present.
3. [Link]
function Home(){
return(
<>
<h1>Home Page</h1>
<p>Flipkart offers a vast array of products ranging from electronics, appliances,
and fashion to books, furniture, and more. The platform has gained widespread
recognition for its user-friendly interface, a diverse product catalog, and competitive
pricing. Additionally, Flipkart has introduced innovative features such as cash-on-
delivery, easy returns, and various payment options, contributing to its widespread
adoption.</p>
</>
)
}
export default Home;
4. [Link]
function About(){
return(
<>
<h1>About Page</h1>
<p>The Flipkart Group
The Flipkart Group is one of India's leading digital commerce entities and includes
group companies Flipkart, Myntra, Flipkart Wholesale, Flipkart Health+, Cleartrip
and ANS Commerce.</p>
</>
)
}
BCSE203E – Web Programming – Lab Manual Page 43 of 54
export default About
5. [Link]
function Product(){
return(
<>
<h1>List of Products</h1>
<ol>
<li>Mobile</li>
<li>Fashion</li>
<li>Electronins</li>
<li>Home and Furniture</li>
<li>Appliances</li>
<li>Travel</li>
<li>Beauty,Toys and more</li>
</ol>
</>
)
}
export default Product
6. [Link]
function Contact(){
return(
<>
<h1>Contact Page</h1>
<p>Flipkart Internet Private Limited,
Buildings Alyssa, Begonia &
Clove Embassy Tech Village,
Outer Ring Road, Devarabeesanahalli Village,
Bengaluru, 560103,
Karnataka, India
CIN : U51109KA2012PTC066107
Telephone: 044-45614700</p></>
)
}
export default Contact
7. For Routing, open the [Link] file and import all the three component files in it.
Also import the following line
1. Write the HTML code with JavaScript to design the sales web app. The web page sells
bags of coffee. You sell regular coffee at Rs.10/bag, you sell decaffeinated coffee at Rs-
8/bag, and you sell mocha coffee for Rs-11/bag. If the user buys more than Rs-100, they
get Rs-15 discount. Use the prompt to ask the user how many bags of regular coffee s/he
wants. Then use the prompt to ask about decaf, and then about mocha. Using the input,
calculate the total amount the user will pay. If the total is over Rs-100, subtract Rs-15 from
their total. Finally write out how much the total will be. Use HTML layouts for design.
2. Write the JavaScript code to perform the following. Use a prompt () function to collect the
student name. Use a switch statement to execute a dialog box displaying the phrase
“Welcome <the entered name>“to the website. Use another prompt () function to
collect the current CGPA as input by the student. If the CGPA entered is above 9.0, throw
a message as “Selected for the Second Round”. If the CGPA is below 9.0, throw the
message as“Enter the First round selection process by providing the E-Mail’. In the third
prompt box get the Mobile number and validate with a JavaScript Regular expression with
10 digits only and give a welcome message with the Customized message of your choice.
3. Create a list of items using ul and li tags . Alternative colors for the backgrounds. There is
space between each item.
6. Build a component with an input field and a button. The component should display a
message based on the user input. Use state to manage the input value.
7. Create a custom hook for handling form input. This hook should manage the state of each
form field and provide functions to update the values. Use this custom hook in a form
component.
8. Build a component that fetches data from an API using the useEffect hook. Display the
fetched data on the page.
9. Develop a web page for online medical store using different components such as home,
contact, product and service. Apply routing concept to allow the user for performing
navigation among different components.
10. Build a website for toy store and create components such as home, Toys category and
contact. Apply different types of CSS for each component to improve the presentation of
web pages.
*****