Node-Js-React-Js-Django - LAB
Node-Js-React-Js-Django - LAB
1
l OM oARc PSD|36 63 2 61 1
2
l OM oARc PSD|36 63 2 61 1
3
l OM oARc PSD|36 63 2 61 1
AIM: Make the above web application responsive web application using Bootstrap framework
DESCRIPTION:
Bootstrap is a popular CSS framework that makes it easy to create responsive web applications.
The previous example can be modified using Bootstrap by following these steps:
Project Structure:
1. index.html - Main HTML file containing the structure of the web application with Bootstrap.
2. script.js - JavaScript file for handling interactions and logic (no changes from the previous
example).
3. styles.css - You can include additional custom styles if needed.
4. images/ - Folder for storing images.
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
rel="stylesheet">
<!-- Custom CSS -->
<link rel="stylesheet" href="styles.css">
<title>Shopping Cart</title>
</head>
<body>
<header class="bg-dark text-white text-center py-3">
<h1>Shopping Cart</h1>
<nav>
<ul class="nav justify-content-center">
<li class="nav-item"><a class="nav-link" href="#catalog">Catalog</a></li>
<li class="nav-item"><a class="nav-link" href="#cart">Cart</a></li>
<li class="nav-item"><a class="nav-link" href="#login">Login</a></li>
<li class="nav-item"><a class="nav-link" href="#register">Register</a></li>
</ul>
</nav>
</header>
<main class="container mt-3" id="content">
<!-- Content will be loaded dynamically using JavaScript -->
</main>
<!-- Bootstrap JS (optional, for certain features) -->
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="script.js"></script>
</body>
</html>
4
l OM oARc PSD|36 63 2 61 1
5
l OM oARc PSD|36 63 2 61 1
AIM:
Use JavaScript for doing client – side validation of the pages implemented in experiment 1: Build a
responsive web application for shopping cart with registration, login, catalog and cart pages using
CSS3 features, flex and grid and experiment 2: Make the above web application responsive web
application using Bootstrap framework
DESCRIPTION:
To perform client-side validation using JavaScript, you can add scripts to validate user inputs on the
registration and login pages.
The modifications for both experiments are listed below.
Experiment 1: Responsive Web Application without Bootstrap
Add the following JavaScript code to script.js:
// Function to validate registration form
function validateRegistration() {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
if (username.trim() === '' || password.trim() === '') {
alert('Please enter both username and password.');
return false;
}
// Additional validation logic can be added as needed
return true;
}
// Function to validate login form
function validateLogin() {
const username = document.getElementById('loginUsername').value;
const password = document.getElementById('loginPassword').value;
if (username.trim() === '' || password.trim() === '') {
alert('Please enter both username and password.');
return false;
}
// Additional validation logic can be added as needed
return true;
}
Modify the HTML login and registration forms:
<!-- Registration Form -->
<form onsubmit="return validateRegistration()">
<!-- ... existing form fields ... -->
<button type="submit">Register</button>
</form>
<!-- Login Form -->
<form onsubmit="return validateLogin()">
<!-- ... existing form fields ... -->
<button type="submit">Login</button>
</form>
6
l OM oARc PSD|36 63 2 61 1
7
l OM oARc PSD|36 63 2 61 1
8
l OM oARc PSD|36 63 2 61 1
9
l OM oARc PSD|36 63 2 61 1
10
l OM oARc PSD|36 63 2 61 1
11
l OM oARc PSD|36 63 2 61 1
12
l OM oARc PSD|36 63 2 61 1
13
l OM oARc PSD|36 63 2 61 1
14
l OM oARc PSD|36 63 2 61 1
15
l OM oARc PSD|36 63 2 61 1
16
l OM oARc PSD|36 63 2 61 1
17
l OM oARc PSD|36 63 2 61 1
18
l OM oARc PSD|36 63 2 61 1
19
l OM oARc PSD|36 63 2 61 1
20
l OM oARc PSD|36 63 2 61 1
21
l OM oARc PSD|36 63 2 61 1
22
l OM oARc PSD|36 63 2 61 1
23
l OM oARc PSD|36 63 2 61 1
24
l OM oARc PSD|36 63 2 61 1
25
l OM oARc PSD|36 63 2 61 1
26
l OM oARc PSD|36 63 2 61 1
27
l OM oARc PSD|36 63 2 61 1
28
l OM oARc PSD|36 63 2 61 1
29
l OM oARc PSD|36 63 2 61 1
30
l OM oARc PSD|36 63 2 61 1
31
l OM oARc PSD|36 63 2 61 1
32
l OM oARc PSD|36 63 2 61 1
33
l OM oARc PSD|36 63 2 61 1
34
l OM oARc PSD|36 63 2 61 1
35
l OM oARc PSD|36 63 2 61 1
14. Create a TODO application in react with necessary components and deploy it into github
AIM: Create a TODO application in react with necessary components and deploy it into github
DESCRIPTION:
Let's create a simple TODO application in React and deploy it to GitHub Pages.
1. Set Up the React App:
npx create-react-app todo-app
cd todo-app
2. Create Necessary Components:
src/components/TodoForm.js:
// src/components/TodoForm.js
import React, { useState } from 'react';
const TodoForm = ({ addTodo }) => {
const [text, setText] = useState('');
const handleSubmit = (e) => {
e.preventDefault();
if (text.trim() !== '') {
addTodo(text);
setText('');
}
};
return (
<form onSubmit={handleSubmit}>
<input type="text" value={text} onChange={(e) => setText(e.target.value)} placeholder="Add a
new todo" />
<button type="submit">Add Todo</button>
</form>
);
};
export default TodoForm;
src/components/TodoList.js:
// src/components/TodoList.js
import React from 'react';
const TodoList = ({ todos, deleteTodo }) => {
return (
<ul>
{todos.map((todo) => (
<li key={todo.id}>
{todo.text}
<button onClick={() => deleteTodo(todo.id)}>Delete</button>
</li>
))}
</ul>
);
};
export default TodoList;
src/App.js:
// src/App.js
import React, { useState } from 'react';
import TodoForm from './components/TodoForm';
36
l OM oARc PSD|36 63 2 61 1
37