Web Tech. Lab Manual
Web Tech. Lab Manual
Create a form having a number of elements (Textboxes, Radio buttons, Checkboxes, and so on). Write
JavaScript code to count the number of elements in a form.
<!DOCTYPE html>
<html>
<head>
<title>Form Elements Count</title>
<script>
function countElements() {
var form = document.getElementById("myForm");
var elements = form.elements;
var count = elements.length;
alert("Number of elements in the form: " + count);
}
</script>
</head>
<br>
<body> <b> Hobbies </body><br>
<br>
1
<body> <b> Country </body><br><br>
<select name="country">
<option value="India">India</option><br>
<option value="usa">USA</option>
<option value="uk">UK</option>
<option value="canada">Canada</option>
</select><br>
<br>
<input type="submit" value="Submit">
</form>
<button onclick="countElements()">Count Elements</button>
</body>
</html>
Result
Thus, the above HTML5 Program for Elements counting and its usage was successfully embedded.
Output
2
Program: 2
Create a HTML form that has number of Textboxes. When the form runs in the Browser fill the Text
boxes with data. Write JavaScript code that verifies that all textboxes has been filled. If a textboxes has
been left empty, popup an alert indicating which textbox has been left empty.
<!DOCTYPE html>
<html>
<head>
<title>Verify Textbox Filling</title>
<script>
function verifyTextboxes() {
var textboxes = document.querySelectorAll('input[type="text"]');
var emptyTextboxes = [];
if (emptyTextboxes.length > 0) {
alert('The following textboxes are empty: ' +
emptyTextboxes.join(', '));
} else {
alert('All textboxes have been filled!');
}
}
</script>
</head>
<body>
<form>
<input type="text" id="textbox1" placeholder="Textbox 1"><br>
<input type="text" id="textbox2" placeholder="Textbox 2"><br>
3
<input type="text" id="textbox3" placeholder="Textbox 3"><br>
<input type="text" id="textbox4" placeholder="Textbox 4"><br>
<input type="text" id="textbox5" placeholder="Textbox 5"><br>
<br>
</form>
</body>
</html>
Result
Thus, the above HTML5 Program for Textboxes and its status of entry was successfully embedded.
Output
4
5
Program: 3
Develop a HTML Form, which accepts any Mathematical expression. Write JavaScript code to Evaluates
the expression and display the result.
<!DOCTYPE html>
<html>
<head>
<title>Math Expression Evaluator</title>
<script>
function evaluateExpression() {
var expression = document.getElementById("expression").value;
var result;
try {
result = eval(expression);
if (isNaN(result)) {
throw new Error("Invalid expression");
}
document.getElementById("result").innerHTML = "Result: " + result;
} catch (error) {
document.getElementById("result").innerHTML = "Error: " +
error.message;
}
}
</script>
</head>
<body>
<h1>Math Expression Evaluator</h1>
<form>
<input type="text" id="expression" placeholder="Enter a mathematical
expression" required><br>
<br>
<input type="button" value="Evaluate" onclick="evaluateExpression()">
</form>
6
<div id="result"></div>
</body>
</html>
Result
Thus, the above HTML5 Program for mathematical express evaluation was successfully embedded.
Output
7
8
Program: 4
Create a page with dynamic effects. Write the code to include layers and basic animation.
<!DOCTYPE html>
<html>
<head>
<title>Dynamic Effects with Layers</title>
<style>
.layer {
position: absolute;
width: 200px;
height: 200px;
background-color: #eaeaea;
border: 1px solid #ccc;
transition: all 0.5s ease-in-out;
}
#layer1 {
top: 50px;
left: 50px;
}
#layer2 {
top: 100px;
left: 100px;
}
#layer3 {
top: 150px;
left: 150px;
}
.layer:hover {
9
transform: scale(1.2);
background-color: #a0a0a0;
border-color: #666;
}
</style>
</head>
<body>
<h1>Dynamic Effects with Layers</h1>
<div class="layer" id="layer1"></div>
<div class="layer" id="layer2"></div>
<div class="layer" id="layer3"></div>
</body>
</html>
Result
Thus, the above HTML5 Program for dynamic effects in animation was successfully embedded.
Output
10
11
Program: 5
Write a JavaScript code to find the sum of N natural Numbers. (Use user-defined function).
<!DOCTYPE html>
<html>
<head>
<title>Sum of N Natural Numbers</title>
<script>
function sumOfNaturalNumbers() {
var n = parseInt(document.getElementById("number").value);
var sum = 0;
Result
Thus, the above HTML5 Java script Program for Sum of N natural number computing was
successfully embedded.
12
Output
13
Program: 6
Write a JavaScript code block using arrays and generate the current date in words, this should include
the day, month and year.
<!DOCTYPE html>
<html>
<head>
<title>Current Date in Words</title>
<script>
// Function to convert a number to its corresponding word
function numberToWord(number) {
var words = ["zero", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "nineteen"];
var tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty",
"seventy", "eighty", "ninety"];
// For numbers greater than 9999, you can add more logic as needed
return "unknown";
}
15
Result
Thus, the above HTML5 Java script Program for date number to word convert computing was
successfully embedded.
Output
16
Program: 7
Create a form for Student information. Write JavaScript code to find Total, Average, Result and Grade.
<!DOCTYPE html>
<html>
<head>
<title>Student Information Form</title>
<script>
function calculateResult() {
// Get the input values from the form
var computers =
parseFloat(document.getElementById("computers").value);
var mathematics =
parseFloat(document.getElementById("mathematics").value);
var skilldev = parseFloat(document.getElementById("skilldev").value);
17
if (averageMarks >= 90) {
grade = "A+";
} else if (averageMarks >= 80) {
grade = "A";
} else if (averageMarks >= 70) {
grade = "B";
} else if (averageMarks >= 60) {
grade = "C";
} else if (averageMarks >= 50) {
grade = "D";
} else {
grade = "E";
}
} else {
result = "Fail";
grade = "N/A";
}
<label for="mathematics">Mathematics:</label>
<input type="number" id="mathematics"><br>
18
<label for="skilldev">Skill Development:</label>
<input type="number" id="skilldev"><br>
<h2>Result:</h2>
<p id="totalMarks"></p>
<p id="averageMarks"></p>
<p id="result"></p>
<p id="grade"></p>
</body>
</html>
Result
Thus, the above HTML5 Java script Program for Students marks system computing was successfully
embedded.
Output
19
20
Program: 8
Create a form for Employee information. Write JavaScript code to find DA, HRA, PF, TAX, Gross pay,
Deduction and Net pay.
<!DOCTYPE html>
<html>
<head>
<title>Employee Information Form</title>
<script>
function calculatePay() {
// Get the input values from the form
var name = document.getElementById("name").value;
var salary = parseFloat(document.getElementById("salary").value);
21
document.getElementById("nameDisplay").innerHTML = "Employee Name: "
+ name;
document.getElementById("daDisplay").innerHTML = "Dearness Allowance
(DA): " + da.toFixed(2);
document.getElementById("hraDisplay").innerHTML = "House Rent
Allowance (HRA): " + hra.toFixed(2);
document.getElementById("pfDisplay").innerHTML = "Provident Fund
(PF): " + pf.toFixed(2);
document.getElementById("taxDisplay").innerHTML = "Tax: " +
tax.toFixed(2);
document.getElementById("grossPayDisplay").innerHTML = "Gross Pay: "
+ grossPay.toFixed(2);
document.getElementById("deductionDisplay").innerHTML = "Total
Deduction: " + totalDeduction.toFixed(2);
document.getElementById("netPayDisplay").innerHTML = "Net Pay: " +
netPay.toFixed(2);
}
</script>
</head>
<body>
<h1>Employee Information Form</h1>
<form>
<label for="name">Employee Name:</label>
<input type="text" id="name"><br>
<label for="salary">Salary:</label>
<input type="number" id="salary"><br>
<h2>Pay Details:</h2>
<p id="nameDisplay"></p>
<p id="daDisplay"></p>
<p id="hraDisplay"></p>
<p id="pfDisplay"></p>
<p id="taxDisplay"></p>
22
<p id="grossPayDisplay"></p>
<p id="deductionDisplay"></p>
<p id="netPayDisplay"></p>
</body>
</html>
Result
Thus, the above HTML5 Java script Program for employee information form computing was
successfully embedded.
Output
23
24
Program: 9
Create a form consists of a two Multiple choice lists and one single choice list
(a)The first multiple choice list, displays the Major dishes available
<!DOCTYPE html>
<html>
<head>
<title>Food Order Form</title>
</head>
<body>
<h1>Food Order Form</h1>
<form>
<label for="majorDishes">Major Dishes:</label>
<select id="majorDishes" multiple>
<option value="pizza">Pizza</option>
<option value="burger">Burger</option>
<option value="pasta">Pasta</option>
<option value="sushi">Sushi</option>
</select><br>
<label for="starters">Starters:</label>
<select id="starters" multiple>
<option value="wings">Chicken Wings</option>
<option value="nachos">Nachos</option>
<option value="bruschetta">Bruschetta</option>
<option value="springRolls">Spring Rolls</option>
</select><br>
Result
Thus, the above HTML5 Java script Program for employee information form computing was
successfully embedded.
Output
26
27