Name : Tanay Saxena
Registration No : 22BDS0049
Ques 1:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ques 1</title>
<style>
.box-contain {
color: rgb(7, 7, 72);
height: 125px;
width: 200px;
background-color: rgb(7, 7, 72);
padding: 10px;
}
</style>
<script>
function remove_item() {
function createTable() {
let rows = parseInt(prompt("Color Added"));
let cols = parseInt(prompt("Color Removed"));
let existingTable = document.getElementById("box-contain");
if (existingTable) {
existingTable.remove();
}
let table = document.createElement("table");
table.id = "box-contain";
table.border = "1";
for (let i = 0; i < rows; i++) {
let row = table.insertRow();
for (let j = 0; j < cols; j++) {
let cell = row.insertCell();
cell.innerHTML = content;
}
}
document.body.appendChild(table);
}
}
</script>
</head>
<body>
<p> <b>Ques-1 (b) - Tanay Saxena 22bds0049</b> </p>
<div class="box-contain">
<select name="Drop-down" id="Drop down "> Select a Color
<option value="Red">Red</option>
<option value="Drop-down">Green</option>
<option value="Drop-down">White</option>
<option value="Drop-down">Black</option>
</select>
<button id="Select_Remove" onclick="remove_item()">Select and Remove
</button>
</div>
</body>
</html>
Output:
Ques 2:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ques 2</title>
<script>
function Verify_capcha() {
let name = document.getElementById("name").value.trim();
let email = document.getElementById("email").value.trim();
let password = document.getElementById("password").value.trim();
let phone = document.getElementById("phone").value.trim();
let age = parseInt(document.getElementById("age").value.trim());
let nameRegex = /^[A-Za-z ]{3,}$/;
let emailRegex = /^\S+@\S+\.\S+$/;
let passwordRegex = /^.{6,}$/;
let phoneRegex = /^[1-9]\d{9}$/;
if (!nameRegex.test(name)) {
alert("Invalid Name: Only letters/spaces and at least 3
characters.");
return false;
}
if (!emailRegex.test(email)) {
alert("Invalid Email format.");
return false;
}
if (!passwordRegex.test(password)) {
alert("Password must be at least 6 characters.");
return false;
}
if (!phoneRegex.test(phone)) {
alert("Phone number must be 10 digits and not start with 0.");
return false;
}
if (isNaN(age) || age <= 0) {
alert("Please enter a valid age.");
return false;
}
alert("Form submitted successfully!");
return true;
}
</script>
<style>
*{
font-weight:900;
padding: 10px;
}
</style>
</head>
<body>
<div>
<form>
<p> <b>Ques-1 (b) - Tanay Saxena 22bds0049</b> </p>
<button id="Generate Capcha" onclick="generate_capcha()">Generate
Capcha </button>
<br>
<br>
<span> User please enter the capcha to verify : </span>
<input type="text" placeholder="Enter Capcha">
<br>
<input type="text" placeholder="Enter name" id="name">
<br>
<input type="text" placeholder="Enter email" id="email">
<br>
<input type="text" placeholder="Enter age" id="age">
<br>
<input type="text" placeholder="password" id="password">
<br>
<button id="Verify Capcha" onclick="Verify_capcha()">Verify Capcha
</button>
<input type="text" placeholder="Enter Capcha">
<button type="submit">Please submit </button>
</form>
</div>
</body>
</html>
Output: