Q10
Q10
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Question 10</title>
</head>
<body>
<h1>Student Registration Form</h1>
<form id="regForm">
<p>
<label for="name">Name:</label>
<input type="name" id="name" placeholder="Enter your full name" />
<span id="name-error" style="color: red;"></span>
</p>
<p>
<label for="email">E-mail Address:</label>
<input type="text" id="email" placeholder="Enter your email" />
<span id="email-error" style="color: red;"></span>
</p>
<p>
<label for="age">Age:</label>
<input type="number" id="age" placeholder="Enter your age" />
<span id="age-error" style="color: red;"></span>
</p>
<p>
<input type="submit" value="Register" />
</p>
</form>
<script>
document.getElementById("regForm").addEventListener("submit", function
(event) {
event.preventDefault(); // Prevent form submission
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Question2</title>
</head>
<body>
<form action="">
<label for="number">Enter Number: </label> <br> <br>
<input type="number" id="number" placeholder="enter number here..."> <br>
<br>
<button id="btn" type="button" onclick="checkPrime()">Check</button>
<p id="result">Result: </p>
</form>
<script>
function checkPrime(){
let num=parseInt(document.getElementById('number').value);
let result=document.getElementById('result');
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Largest and Smallest</title>
</head>
<body>
<h1>Find Largest and Smallest Numbers</h1>
<p>
<label for="array">Enter numbers (comma separated):</label>
<input type="text" id="array" placeholder="e.g. 5,2,9,1,3" />
</p>
<button onclick="findLargestSmallest()">Find</button>
<p id="result"></p>
<script>
function findLargestSmallest() {
const input = document.getElementById("array").value;
const arr = input.split(',').map(Number);
if (arr.length === 0) {
document.getElementById("result").textContent = "Array is empty.";
return;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sum of Array Elements</title>
</head>
<body>
<h1>Sum of Array Elements</h1>
<p>
<label for="array">Enter numbers (comma separated):</label>
<input type="text" id="array" placeholder="e.g. 5,2,9,1,3" />
</p>
<button onclick="sumArray()">Find Sum</button>
<p id="result"></p>
<script>
function sumArray() {
const input = document.getElementById("array").value;
const arr = input.split(',').map(Number);
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}
<script>
function redirect() {
const menu = document.getElementById('menu');
const selectedValue = menu.value;
if (selectedValue) {
window.location.href = selectedValue; // Redirect to the selected
site
}
}
</script>
</body>
</html> -->
<!DOCTYPE html>
<html>
<head>
<title>Change Window Content</title>
</head>
<body>
<h2 id="content">Welcome to My Website!</h2>
<button onclick="changeContent()">Change Content</button>
<script>
function changeContent() {
// Changing the content of the window
document.getElementById("content").innerHTML = "You have clicked the
button!";
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login validation</title>
</head>
<body>
<form onsubmit="return false;">
<label for="username">Enter User ID: </label>
<input type="text" id="userId" placeholder="enter user id here...">
<br><br>
<label for="password">Enter Password: </label>
<input type="password" id="password" placeholder="enter password here...">
<br><br>
<button id="btn" onclick="validateForm()">Login</button>
</form>
<p id="loginStatus">Login Status: </p>
<script>
function validateForm(){
let userId=document.getElementById('userId').value.trim();
let password=document.getElementById('password').value.trim();
let loginStatus=document.getElementById('loginStatus');
switch(userId){
case "John":
if(password==="john123"){
loginStatus.textContent="Valid Credentials!"
} else {
loginStatus.textContent="Invalid Credentials"
}
break;
case "Bobby":
if(password==="bobby123"){
loginStatus.textContent="Valid Credentials!"
} else {
loginStatus.textContent="Invalid Credentials"
}
break;
case "James":
if(password==="james123"){
loginStatus.textContent="Valid Credentials!"
} else {
loginStatus.textContent="Invalid Credentials"
}
break;
default:
loginStatus.textContent="Invalid credentials";
}
}
</script>
</body>
</html>
<html>
<head>
<title>Using Intrinsic JavaScript Functions</title>
</head>
<body>
<FORM name="contact" action="#" method="post">
<P>
First Name: <INPUT type="text" name="Fname"/> <BR>
Last Name: <INPUT type="text" name="Lname"/><BR>
Email: <INPUT type="text" name="Email"/><BR>
<img src="image1.jpeg"
onclick="javascript:document.forms.contact.submit()"/>
<img src="image2.jpeg"
onclick="javascript:document.forms.contact.reset()"/>
</P>
</FORM>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script>
function storeCookie() {
let uname = document.getElementById('uname').value;
let pwd = document.getElementById('pwd').value;
let unameCookie = document.cookie = "Username=" + uname + ";"
let pwdCookie = document.cookie = "Password=" + pwd + ";"
alert("Cookie Stored\n" + unameCookie + " , " + pwdCookie);
}
</script>
</head>
<body>
<form name="myForm">
Enter Username <input type="text" id="uname" /><br />
Enter Password <input type="password" id="pwd" /><br />
<input type="button" value="Submit" onclick="storeCookie()" />
<p id="panel"></p>
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Banner Ads</title>
<script type="text/javascript">
let banners = ['image1.jpeg', 'image2.jpeg', 'image3.jpeg']; // Array of
banner images
let links = ['http://google.com', 'http://vpt.edu.in',
'http://msbte.org.in']; // Array of URLs
let currentBanner = 0;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elegant Calculator</title>
</head>
<body>
<h1>Welcome to Your Elegant Calculator</h1>
<form>
<label for="firstNumber">First Number: </label>
<input type="text" id="firstNumber"><br><br>
function divideNumbers() {
let firstNumber =
parseFloat(document.getElementById("firstNumber").value);
let secondNumber =
parseFloat(document.getElementById("secondNumber").value);
let result = firstNumber / secondNumber;
document.getElementById("calculationResult").innerHTML = `Result: $
{result}`;
}
function addNumbers() {
let firstNumber =
parseFloat(document.getElementById("firstNumber").value);
let secondNumber =
parseFloat(document.getElementById("secondNumber").value);
let result = firstNumber + secondNumber;
document.getElementById("calculationResult").innerHTML = `Result: $
{result}`;
}
function subtractNumbers() {
let firstNumber =
parseFloat(document.getElementById("firstNumber").value);
let secondNumber =
parseFloat(document.getElementById("secondNumber").value);
let result = firstNumber - secondNumber;
document.getElementById("calculationResult").innerHTML = `Result: $
{result}`;
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String Length Example</title>
</head>
<body>
<p id="demo"></p>
<script>
// Function to return the length of the string
function len(text) {
return text.length;
}
// Displaying the length of the string "Information"
document.getElementById("demo").innerHTML = "Length of string: " +
len("Information Technology");
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email validation using RegExp</title>
</head>
<body>
<script>
function emailValidation(email){
let emailRegEx = /^\w+([/.-]?\w+)*@\w+([/.-]?\w+)*(\.\w{2,3})+$/;
//let emailRegEx = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(emailRegEx.test(email)){
document.write("Valid Email");
} else {
document.write("Invalid Email");
}
}
emailValidation("[email protected]")
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Book Discounts on Hover</title>
</head>
<body>
<h2>Books and Discounts</h2>
<img id="bookImage" src="image1.jpeg" width="200" height="150" alt="Book Image"
/>
<br><br>
<!-- Use hover (onmouseover) to display the popup with discount info -->
<img src="image1.jpeg" width="100" height="100" alt="Book 1"
onmouseover="showDiscount(1)" />
<img src="image2.jpeg" width="100" height="100" alt="Book 2"
onmouseover="showDiscount(2)" />
<img src="image3.jpeg" width="100" height="100" alt="Book 3"
onmouseover="showDiscount(3)" />
<script>
function showDiscount(bookId) {
let popupWindow;
if (bookId === 1) {
document.getElementById("bookImage").src = "image1.jpeg";
popupWindow = window.open('', 'discountWindow',
'height=100,width=200,left=500,top=200');
popupWindow.document.write("Discount is 50%");
}
if (bookId === 2) {
document.getElementById("bookImage").src = "image2.jpeg";
popupWindow = window.open('', 'discountWindow',
'height=100,width=200,left=500,top=200');
popupWindow.document.write("Discount is 40%");
}
if (bookId === 3) {
document.getElementById("bookImage").src = "image3.jpeg";
popupWindow = window.open('', 'discountWindow',
'height=100,width=200,left=500,top=200');
popupWindow.document.write("Discount is 20%");
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Dropdown Redirection</title>
</head>
<body>
<h3>Select a site to visit:</h3>
<select id="siteSelector" onchange="redirectToSite()">
<option value="">--Select an option--</option>
<option value="https://www.aicte-india.org">AICTE</option>
<option value="https://dtemaharashtra.gov.in">DTE</option>
<option value="https://msbte.org.in">MSBTE</option>
<option value="https://www.google.com">Google</option>
</select>
<script>
function redirectToSite() {
// Get the selected value from the dropdown
const selectedOption = document.getElementById("siteSelector").value;
<script>
const message = "Welcome to the Mystic World of JavaScript ";
const statusBar = document.getElementById("statusBar");
let index = 0;
function crawlMessage() {
statusBar.innerText = message.substring(index) + message.substring(0, index);
index = (index + 1) % message.length;
}
if (document.getElementById("tea").checked) {
dropdown.innerHTML = `
<option>Green tea</option>
<option>Milk tea</option>
<option>Black tea</option>
`;
} else if (document.getElementById("coffee").checked) {
dropdown.innerHTML = `
<option>Cappuccino</option>
<option>Latte</option>
<option>Espresso</option>
`;
} else if (document.getElementById("softDrink").checked) {
dropdown.innerHTML = `
<option>MAAZA</option>
<option>SPRITE</option>
<option>COCA-COLA</option>
`;
}
}
</script>
</head>
<body>
<h3>Select Beverage:</h3>
<label>
<input type="radio" id="tea" name="beverage" onclick="updateDropdown()">
TEA
</label><br>
<label>
<input type="radio" id="coffee" name="beverage" onclick="updateDropdown()">
COFFEE
</label><br>
<label>
<input type="radio" id="softDrink" name="beverage"
onclick="updateDropdown()"> SOFT DRINK
</label>
<h3>Dropdown List:</h3>
<select id="dropdown">
<option>Select a beverage first</option>
</select>
</body>
</html>