IP Codes
IP Codes
#> Write a JavaScript to check if the password and confirm password are the
same or not.
<!DOCTYPE html>
<html>
<head>
<title>Check Password</title>
<script>
function checkPassword() {
const password = document.getElementById("password").value;
const confirmPassword = document.getElementById("confirmPassword").value;
if (password === confirmPassword) {
alert("Passwords match!");
} else {
alert("Passwords do not match!");
}
}
</script>
</head>
<body>
<form onsubmit="event.preventDefault(); checkPassword();">
<label for="password">Password:</label>
<input type="password" id="password" required><br>
<label for="confirmPassword">Confirm Password:</label>
<input type="password" id="confirmPassword" required><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
2. #> Write a JavaScript that reads ten numbers and displays the count of
negative numbers, the count of positive numbers, and the count of zero from
the list.
<!DOCTYPE html>
<html>
<head>
<title>Count Numbers</title>
<script>
function countNumbers() {
const numbers = prompt("Enter 10 numbers separated by spaces:")
.split(" ").map(Number);
let positive = 0, negative = 0, zero = 0;
numbers.forEach(num => {
if (num > 0) positive++;
else if (num < 0) negative++;
else zero++;
});
if (!email.includes("@") || !email.includes(".")) {
alert("Enter a valid email address!");
return false;
}
if (!name) {
alert("Name cannot be empty!");
return false;
}
if (password.length < 6) {
alert("Password must be at least 6 characters long!");
return false;
}
alert("Validation successful!");
return true;
}
</script>
</head>
<body>
<form onsubmit="return validateUserInput();">
<label for="name">Name:</label>
<input type="text" id="name" required><br>
<label for="password">Password:</label>
<input type="password" id="password" required><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
5. #> Create an external stylesheet and link it to an HTML form. The stylesheet
should include the following:
a. A header with red text and a yellow background.
b. A double-lined border table with 5 rows and 3 columns.
c. First column: Sr. No. of the product; second column: image with
hyperlink and product name; third column: description of the product.
<!DOCTYPE html>
<html>
<head>
<title>Styled Form</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>Product Table</header>
<table>
<tr>
<th>Sr. No.</th>
<th>Product</th>
<th>Description</th>
</tr>
<tr>
<td>1</td>
<td><a href="#"><img src="product1.jpg" alt="Product 1" width="50">
Product 1</a></td>
<td>High-quality product</td>
</tr>
<tr>
<td>2</td>
<td><a href="#"><img src="product2.jpg" alt="Product 2" width="50">
Product 2</a></td>
<td>Durable and reliable</td>
</tr>
<tr>
<td>3</td>
<td><a href="#"><img src="product3.jpg" alt="Product 3" width="50">
Product 3</a></td>
<td>Best value for money</td>
</tr>
<tr>
<td>4</td>
<td><a href="#"><img src="product4.jpg" alt="Product 4" width="50">
Product 4</a></td>
<td>Stylish and modern</td>
</tr>
<tr>
<td>5</td>
<td><a href="#"><img src="product5.jpg" alt="Product 5" width="50">
Product 5</a></td>
<td>Eco-friendly product</td>
</tr>
</table>
</body>
</html>
header {
text-align: center;
color: red;
background-color: yellow;
font-size: 24px;
padding: 10px;
}
table {
width: 100%;
border-collapse: collapse;
border: 3px double black;
margin: 20px 0;
}
th, td {
border: 1px solid black;
padding: 10px;
text-align: center;
}
img {
width: 50px;
height: auto;
}
6. #> Write code to drag an image from outside the box and drop it inside the box
using React JS.
import React, { useState } from 'react';
function DragDrop() {
const [dropped, setDropped] = useState(false);
return (
<div>
<h1>Drag and Drop</h1>
<div
onDrop={handleDrop}
onDragOver={handleDragOver}
style={{
width: '300px',
height: '300px',
border: '2px dashed #000',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
{dropped ? <img src="image.jpg" alt="Dropped"
style={{ width: '100px' }} /> : 'Drag an image here'}
</div>
<img
src="image.jpg"
alt="Draggable"
draggable
style={{ width: '100px', marginTop: '20px' }}
/>
</div>
);
}
function HelloWorld() {
return <h1>Hello World</h1>;
}
if (!nameRegex.test(name)) {
alert('Name should contain only alphabets (A-Z).');
return false;
}
if (!emailRegex.test(email)) {
alert('Email ID should contain "@" symbol.');
return false;
}
if (!passwordRegex.test(password)) {
alert('Password must have at least 1 uppercase letter, 1 digit, 1
special character, and be at least 8 characters long.');
return false;
}
<label for="age">Age:</label>
<input type="number" id="age" name="age" required><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
11. #> Write a JSP program to perform basic arithmetic operations: addition,
subtraction, division, and multiplication.
<!DOCTYPE html>
<html>
<head>
<title>Arithmetic Operations</title>
</head>
<body>
<form method="POST">
<label>Enter First Number:</label>
<input type="number" name="num1" required><br>
<label>Enter Second Number:</label>
<input type="number" name="num2" required><br>
<button type="submit">Calculate</button>
</form>
<%
if (request.getMethod().equals("POST")) {
double num1 = Double.parseDouble(request.getParameter("num1"));
double num2 = Double.parseDouble(request.getParameter("num2"));
try {
// Establishing connection
Connection connection = DriverManager.getConnection(
url, username, password);
System.out.println("Connected to the database.");
// Creating a statement
Statement statement = connection.createStatement();
// Executing a query
String query = "SELECT * FROM products";
ResultSet resultSet = statement.executeQuery(query);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$errors[] = "Name is required.";
} else {
$name = htmlspecialchars($_POST["name"]);
}
if (empty($_POST["email"])) {
$errors[] = "Email is required.";
} elseif (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
$errors[] = "Invalid email format.";
} else {
$email = htmlspecialchars($_POST["email"]);
}