Answer of Web
Answer of Web
1. A) Create the HTMI structure for this webpage using basic HTML tags with float layout.
You are developing a website for a news organization. The homepage needs to divided into
different sections, such "Technology." Implement the HTML structure using the tag to
organize these conten "Breaking News," "Politics," VIT News should be center-text
background is Green, Text is bold, italic red color. Divide the sections -Bold and italic and
green color, it should be highlighted. If you click any section it goes to display descriptio
Use click event: Include Section and article in the item of Technology. Footer Display
@copy right 2024 VIT Vellore. Highlight yellow and text color
<!DOCTYPE html>
<html>
<head>
<title>News Homepage</title>
<style>
body {
header {
text-align: center;
background-color: green;
font-weight: bold;
font-style: italic;
color: red;
padding: 10px;
font-size: 24px;
}
.section {
float: left;
width: 30%;
margin: 1%;
padding: 10px;
font-weight: bold;
font-style: italic;
color: green;
background-color: #f0f0f0;
cursor: pointer;
.clear {
clear: both;
#description {
margin-top: 20px;
padding: 10px;
footer {
margin-top: 20px;
background-color: yellow;
color: blue;
text-align: center;
padding: 10px;
</style>
<script>
function showDescription(sectionName) {
let desc = {
};
</script>
</head>
<body>
<header>VIT News</header>
Technology
<section>
<article>
</article>
</section>
</div>
<div class="clear"></div>
<div id="description"></div>
</body>
</html>
B) You've been tasked with creating a simple Student Enrolment application that fetches
student data from a Mysql table studen info and displays it to the user using PHP. The
application should allow enter a student name in an input field and display the information.
1. Display an input field and a button labeled "Get Student Info". 2. When the user enters a
Student ID in the input field and clicks the "Get Student Info" button, the application should
fetch student info from a Mysal table. 3. Display the details for the entered ID. 4. Handle
errors gracefully. If the city name is not found or there's an issue with Mysql request,
display an appropriate message to the user.
<!DOCTYPE html>
<html>
<head>
<title>Student Enrolment</title>
</head>
<body>
</form>
<?php
If (isset($_POST[‘get_info’])) {
$student_id = trim($_POST[‘student_id’]);
If (empty($student_id)) {
} elseif (!ctype_digit($student_id)) {
Echo “<p style=’color:red;’>Invalid Student ID. Please enter numeric digits only.</p>”;
} else {
// Database connection
If ($conn->connect_error) {
} else {
$stmt = $conn->prepare($sql);
If ($stmt) {
$stmt->bind_param(“s”, $student_id);
$stmt->execute();
$result = $stmt->get_result();
If ($result->num_rows > 0) {
} else {
$stmt->close();
} else {
$conn->close();
?>
</body>
</html>
2. A) You are tasked with deaigning the user interface for an c-commerce website. The
design team has provided specific guidelines for borders and margins to create a visually
appealing and user-friendly layout. Here are the details: 1. Product Cards: Apply a subtle 1-
pixel solid border with a light gray color (#dedede) to all product cards. Set the margin
around each product card to 15 pixels on all sides for a consistent spacing. Buttons: Give
the category buttons a 2-pixel solid border with a border-radius of 5 pixels and a color of
#3498db. 2. Category Apply a margin of 10 pixels on the top and bottom, and 15 pixels on
the left and right to ensure proper spacing 3. Checkout Form: Create a 3-pixel dashed
border with a color of #27ae60 for the entire checkout form. Set the margin to 20 pixels on
the top, 10 pixels on the right, 20 pixels on the bottom, and 10 pixels on the left. Apply a 2-
pixel solid border with a color of #39e12 to the footer. Set the margin for the footer to 30
pixels on all sides. Footer Section
<!DOCTYPE html>
<html>
<head>
<title>E-Commerce UI</title>
<style>
Body {
/* Product Cards */
.product-card {
Margin: 15px;
Padding: 10px;
Width: 200px;
Display: inline-block;
/* Category Buttons */
.category-button {
Border-radius: 5px;
Background-color: white;
Color: #3498db;
Cursor: pointer;
/* Checkout Form */
.checkout-form {
Padding: 15px;
/* Footer */
Footer {
Margin: 30px;
Padding: 10px;
Text-align: center;
/* Registration Form */
.registration-form {
Padding: 20px;
Width: 300px;
.registration-form input {
Width: 100%;
Margin-bottom: 10px;
Padding: 8px;
.error {
Color: red;
Font-size: 0.9em;
Margin-bottom: 10px;
.success {
Color: green;
Font-size: 1em;
</style>
</head>
<body>
<h2>Products</h2>
<div class=”product-card”>
<h4>Product 1</h4>
<p>$19.99</p>
</div>
<div class=”product-card”>
<h4>Product 2</h4>
<p>$29.99</p>
</div>
<h2>Categories</h2>
<button class=”category-button”>Electronics</button>
<button class=”category-button”>Fashion</button>
<h2>Checkout</h2>
<form class=”checkout-form”>
<label>Shipping Address</label><br>
<label>Payment Method</label><br>
<input type=”text” placeholder=”Enter payment details”>
</form>
<h2>User Registration</h2>
<button type=”submit”>Register</button>
</form>
<footer>
© 2024 My E-Commerce
</footer>
<script>
Let formData = {
Username: ‘’,
Email: ‘’,
Password: ‘’,
confirmPassword: ‘’
};
Function handleChange(event) {
formData[name] = value;
Function isValidEmail(email) {
Return regex.test(email);
Function validateForm(data) {
If (!data.username.trim()) {
If (!data.email.trim()) {
} else if (!isValidEmail(data.email)) {
If (!data.password) {
If (!data.confirmPassword) {
Return errors;
Function handleSubmit(event) {
Event.preventDefault();
Document.getElementById(“formSuccess”).textContent = “”;
If (Object.keys(errors).length === 0) {
Document.getElementById(“registrationForm”).reset();
} else {
Document.getElementById(`${key}Error`).textContent = errors[key];
</script>
</body>
</html>
: B) You are developing a user registration feature for a web application. The registration
form includes fields for username, email, password, and password confirmation. Your task
is to implement client-side validation to ensure that users enter valid information before
submitting the form. Additionally, you need to provide clear error messages for each
validation rule and prevent form submission if there are any errors. Write code to validate
the form inputs on the elient side using JavaScript, checking for the following conditions:
Use formData state is used to manage form input values. Use handleChange function
updates the formData state when input values change Use handleSubmit function is called
when the form is submitted. It validates the form data and either submits the form or sets
validation errors. Use validateForm function performs validation on form data and returns
an object containing validation errors. Use is ValidEmail function checks if the email format
is valid using a regular expression.
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
<style>
body {
margin: 30px;
h2 {
color: #333;
input {
width: 300px;
padding: 8px;
margin-bottom: 10px;
display: block;
button {
background-color: #3498db;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
button:hover {
background-color: #2980b9;
.error {
color: red;
font-size: 0.9em;
margin-bottom: 10px;
.success {
color: green;
font-size: 1em;
margin-top: 15px;
}
</style>
</head>
<body>
<h2>User Registration</h2>
<button type="submit">Register</button>
</form>
<script>
let formData = {
username: '',
email: '',
password: '',
confirmPassword: ''
};
function handleChange(event) {
formData[name] = value;
function isValidEmail(email) {
return regex.test(email);
function validateForm(data) {
if (!data.username.trim()) {
if (!data.email.trim()) {
errors.email = "Email is required.";
} else if (!isValidEmail(data.email)) {
if (!data.password) {
if (!data.confirmPassword) {
return errors;
function handleSubmit(event) {
event.preventDefault();
if (Object.keys(errors).length === 0) {
document.getElementById("registrationForm").reset();
} else {
document.getElementById(`${key}Error`).textContent = errors[key];
</script>
</body>
</html>
6. A) You're tasked with developing a web page featuring a text box where users can input a
4-digit OTP generated randomly. The entered vakue must match with the generated value,
when clicks a button. Here's a breakdown of the scenario and associated tasks: Designing
the User Interface: Create an HTML. file (home.html) to serve as the main page. Design the
layout with a text box for entering the 4-digit OTP value and a submit button. Implementing
JavaScript String: code to generate random value and validate the value. Write JavaScript
string function
<!DOCTYPE html>
<html>
<head>
<title>OTP Verification</title>
<style>
Body {
Padding: 50px;
Background-color: #f0f0f0;
.container {
Background: white;
Padding: 20px;
Width: 300px;
Margin: auto;
Border-radius: 8px;
Text-align: center;
Input {
Padding: 10px;
Margin: 10px 0;
Width: 100%;
Font-size: 16px;
Button {
Padding: 10px;
Background-color: #2ecc71;
Color: white;
Border: none;
Font-size: 16px;
Width: 100%;
Cursor: pointer;
#message {
Margin-top: 10px;
Font-weight: bold;
</style>
</head>
<body>
<div class=”container”>
<h2>Enter OTP</h2>
<div id=”message”></div>
</div>
<script>
Function validateOTP() {
messageBox.style.color = “green”;
} else {
messageBox.style.color = “red”;
</script>
</body>
</html>
B) You are tasked with creating a simple Todo search application. The application should
allow users to search for Todo list by entering a keyword in an input field. Upon searching,
the application should fetch data from a Mysql table name Todo info and display a list of
events matching the search criteria. Requirements: Display an input field and a button
labelled "Search" 2. When the user enters a keyword in the input field and clicks the
"Search" button, the application should fetch data from Mysql table. 3. Display a list of
events matching the search criteria, showing at least the event name and time created
date. 4. Handle errors gracefully. If there's an issue with the request or no events are found
the given keyword, display an appropriate error message to the user. 5. Write a PHP
program to handle this request, populate and fetch the details from the table manually
using Mysql command
USE todo_app;
Event_name VARCHAR(255),
);
◼ Sample data
(‘Buy groceries’),
(‘Complete assignment’);
```
```php
<?php
If ($conn->connect_error) {
Exit;
$likeKeyword = “%$keyword%”;
$stmt->bind_param(“s”, $likeKeyword);
$stmt->execute();
$result = $stmt->get_result();
$events = [];
$events[] = $row;
}
If (count($events) === 0) {
} else {
Echo json_encode($events);
$stmt->close();
$conn->close();
?>
```
```html
<!DOCTYPE html>
<html>
<head>
<title>Todo Search</title>
<style>
Body {
Padding: 30px;
}
Input, button {
Padding: 10px;
Font-size: 16px;
Margin: 5px;
.event {
Margin-top: 10px;
Padding: 8px;
</style>
</head>
<body>
<button onclick=”searchTodo()”>Search</button>
<div id=”results”></div>
<script>
Function searchTodo() {
resultsDiv.innerHTML = “Searching…”;
fetch(`search_todo.php?keyword=${encodeURIComponent(keyword)}`)
.then(data => {
resultsDiv.innerHTML = “”;
if (data.error) {
resultsDiv.textContent = data.error;
} else {
Data.forEach(event => {
div.className = “event”;
div.innerHTML =
`<strong>${event.event_name}</strong><br><small>${event.created_at}</small>`;
resultsDiv.appendChild(div);
});
})
.catch(error => {
console.error(error);
});
</script>
</body>
</html>
```
3B
** Question:**
Design a webpage for the above registration form, validate the form using HTML, and
validate the following criteria using PHP with regular expressions:
- true otherwise
** Answer:**
**HTML (registration.html):**
```html
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h2>Registration Form</h2>
<form method=”POST” action=”validate.php”>
Sex:
Language:
</form>
</body>
</html>
```
**PHP (validate.php):**
```php
<?php
$errors = [];
If ($_SERVER[“REQUEST_METHOD”] == “POST”) {
$userid = $_POST[‘userid’];
$phone = $_POST[‘phone’];
$email = $_POST[‘email’];
$sex = isset($_POST[‘sex’]) ? $_POST[‘sex’] : ‘’;
If (!preg_match(‘/^\d{5,12}$/’, $userid)) {
If (!preg_match(‘/^\d{7,12}$/’, $phone)) {
If (strlen($email) < 6 || strpos($email, ‘@’) === false || strpos($email, ‘.’) === false) {
If (empty($sex)) {
If (empty($language)) {
If (empty($errors)) {
} else {
Echo “<h3>Validation Errors:</h3><ul>”;
Echo “</ul>”;
?>
```