Database
Database
Requirements:
Program editor (Notepad, Notepad++, Netbeans), Browser (Chrome, Firefox)
Program:
Common content in every.htmlfile
!
< DOCTYPE html
>
<html
lang
=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width,
initial-scale=1.0"
>
<title>
Shopping Cart
</title>
<link
rel
=
"stylesheet"
href
=
"style.css"
>
/head>
<
<body>
<header>
<h1>
Welcome to My Store
</h1>
<nav>
<ul>
<li><a
href
=
"index.html"
>
Home
</a></li>
<li><a
href
=
"register.html"
>
Register
</a></li>
<li><a
href
=
"login.html"
>
Login
</a></li>
<li><a
href
=
"catalog.html"
>
B
rowse Catalog</a></li>
</ul>
</nav>
</header>
<main>
Change Content according to page
</main>
/body>
<
</html>
Note:write above code in all html pages and change<main>section according to page requirement.
Index.html
<main>
<h3>
Objective:
</h3>
<p>
Develop
a
responsive web
application for
a shopping cart featuring
registration,
login, catalog, and
cart pages,
leveraging CSS3 functionalities,
flexbox, and grid layout.
</p>
<h3>
Description:
</h3>
<p>
The
project entails utilizing HTML,
CSS,
and JavaScript to construct
a
responsive
web
application. Specifically, it
involves creating a
shopping cart
platform
with
essential functionalities such
asuserregistration, login, product
catalog
browsing, and
managing
cart contents.
This
will be
achieved through
the
integration
of
modern CSS3
features along
with
the
flexible layout capabilities
provided by flexbox and grid systems.
</p>
</main>
login.html
<main>
<h2>
Login Page
</h2>
<form
action=
"#"
>
<label
for
=
"username"
>
Username:
</label>
<input
type=
"text"
id=
"username"
name
=
"username"
>
<label
for
=
"password"
>
Password:
</label>
<input
type=
"password"
id=
"password"
name=
"password"
>
<input
type=
"submit"
id
=
"Login"
name
=
"Login"
value
=
"
Login"
/>
</form>
</main>
register.html
<main>
<h2>
Register
</h2>
<form
action
=
"#"
>
<label for=
"username"
>
U
sername:</label>
<input
type
=
"text"
id=
"username"
name=
"username"
>
<label
for
=
"email"
>
Email:
</label>
<input
type
=
"email"
id
=
"email"name
=
"email"
>
<label
for
=
"password"
>
Password:
</label>
<input
type
=
"password"
id=
"password"
name=
"password"
>
<input
type
=
"submit"
id
=
"Register"
name=
"Register"
value
=
"Register"
/>
</form>
</main>
catalog.html
<main>
<h2>
Product Catalog
</h2>
<div
class=
"
product-grid" >
<article
class=
"
product">
<img
src=
"html5.jpeg"
alt =
"HTML 5 Notes"
>
<h3>
HTML 5 Notes
</h3>
<p>₹
20.00
</p>
<button
data-product-id
=
"1"
class
=
"add-to-cart"
onclick
=
"
goToCart(this)" >
Add to Cart
</button>
</article>
<article
class=
"
product">
<img
src=
"CSS.jpeg"
alt=
"CSS Notes"
>
<h3>
CSS Notes
</h3>
<p>₹
15.00
</p>
<button
data-product-id
=
"2"
class
=
"add-to-cart"
onclick
=
"
goToCart(this)" >
Add to Cart
</button>
</article>
<article
class=
"
product">
<img
src=
"NodeJs.jpeg"
alt=
"Node Js Notes"
>
<h3>
Node JS Notes
</h3>
<p>₹
40.00
</p>
<button
data-product-id
=
"3"
class
=
"add-to-cart"
onclick
=
"
goToCart(this)" >
Add to Cart
</button>
</article>
</div>
</main>
<script
src
=
"catalog.js"
></script>
cart.html
<main>
<h2>
Shopping Cart
</h2>
<div
id
=
"cart-items"
>
<!-- Cart items will be displayed here dynamically
-->
</div>
</main>
<script
src
=
"cart.js"
></script>
style.css
/* General Styles */
body
{
font-family
: sans-serif;
margin
: 0;
padding
: 0;
}
header
{
background-color
: #f0f0f0;
padding
: 10px;
text-align
: center;
}
main
{
padding
: 20px;
}
h2
{
t
ext-align:center;}
nav ul li
{
margin-right
: 20px;
padding
:10px 20px;
background-color
:#4CAF50;
border-radius
: 4px;
}
nav ul li
:
last-child
{
margin-right
: 0;
}
nav ul li a
{
text-decoration
: none;
color
:#fff;
padding
:20px;
cursor
: pointer;
}
nav ul li a
:
hover
{
color
:#000;}
*Form Styles*/
/
form
{
display
: flex;
flex-direction
: column;
align-items
: center;
}
input
{
margin-top
: 5px;
margin-bottom
: 10px;
}
.
p
roduct
{
background-color
: #fff;
padding
: 10px;
text-align
: center;
border-radius
: 5px;
}
.
p
roduct
img{
width
: 100%;
object-fit
: cover;
}
.p
roduct
button
{
background-color
: #4CAF50;
border
: none;
color
: white;
padding
: 10px 20px;
text-align
: center;
text-decoration
: none;
display
: inline-block;
font-size
: 16px;
margin
: 4px 2px;
cursor
: pointer;
border-radius
: 4px;
}
.
p
roduct
button
:
hover
{
background-color
: #45a049;}
catalog.js
// Redirect from catalog to cart
function
goToCart
(
button
)
{
const
productId=
button.
g
etAttribute
(
'data-product-id'
);
// Redirect to the cart page with the selected
product ID
window
.
location
.
href
=̀cart.html?product=${productId}`;
}
cart.js
/ Call addToCart function when the page loads
/
document
.
a
ddEventListener
(
'DOMContentLoaded'
,
function
()
{
addToCart
();
});
function
addToCart
()
{
// Parse the query string from the URL
const
queryString
=
window
.
location
.
search
;
const
urlParams
=
new
URLSearchParams(
queryString
);
function
addToCartWithProductId
(
productId
)
{
const
products
=
[
{
id
:
1
,
src
:
'html5.jpeg'
,
name
:
'HTML 5 Notes'
,
price:
20.00},
{
id
:
2
,
src
:
'CSS.jpeg'
,
name
:
'CSS Notes'
,
price
:
15.00},
{
id
:
3
,
src
:
'NodeJs.jpeg'
,
name
:
'Node JS
Notes'
,
price:
40.00}
];
// Find the product with the given ID
const
selectedProduct
=
products.
find
(
product
=>
product
.
id
==productId
);
function
displayCartItems
(
items
)
{
const
cartItemsDiv
=
document.
getElementById
(
'cart-items'
);
cartItemsDiv
.
innerHTML
=
''
;
// Clear existing
content
items
.
forEach
(
item
=>
{
const
itemDiv =
document.
createElement
(
'div'
);
itemDiv
.
classList
.
add
(
'cart-item'
);
itemDiv
.
innerHTML
=̀<img src="${item.src}"/>
<h3>${item.name}</h3>
<p>₹ ${item.price.toFixed(2)}</p>`
;
cartItemsDiv
.
appendChild
(
itemDiv
);
});
}
Outputs