Web Tech Lab
Web Tech Lab
PAGE
S.NO DATE PROGRAM TITLE SIGN
NO
EX NO:01 Create a form having number of elements (Textboxes, Radio buttons,
Date: Checkboxes, and so on).
Aim:
To write a program to a form having number of elements.
Algorithm:
Step 2: The form includes textboxes, radio buttons, checkboxes, and a button.
Each element is uniquely identifiable
Step 3: It then updates the content of specific <p> elements with the count of each
Type of element
Step 4: The results are displayed in <p> elements with IDs textbox Count,
Radio Button Count, checkbox Count, and button Count
Step 5: When you open this HTML file in a web browser and click
the "Count Elements" button,
Step 6: It will display the counts of textboxes, radio buttons, checkboxes, and buttons in
the form.
<!DOCTYPE html>
<head>
<title>Form Element Counter</title>
</head>
<body>
<h1>Form Element Counter</h1>
<form id="myForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br>
<label>Gender:</label>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<label>Interests:</label>
<input type="checkbox" id="sports" name="interests" value="sports">
<label for="sports">Sports</label>
<input type="checkbox" id="music" name="interests" value="music">
<label for="music">Music</label><br>
<button type="button" onclick="countElements()">Count Elements</button>
</form>
<h2>Element Counts</h2>
<p id="textboxCount"></p>
<p id="radioButtonCount"></p>
<p id="checkboxCount"></p>
<p id="buttonCount"></p>
</body>
</html>
OUTPUT
RESULT:
Thus, the given program has been executed successfully and output verified.
EX NO:02 Create a HTML form that has number of Textboxes. When the form runs in
Date: the Browser fill the Text boxes with data.
Aim:
To write a HTML form that has number of Textboxes. When the form runs in
the Browser fill the Text boxes with data
Algorithm:
<!DOCTYPE html>
<head>
<title>Textbox Validation</title>
<script>
function validateForm() {
// Get the form element by its ID
var form = document.getElementById('myForm');
// Get all textboxes within the form
var textboxes = form.querySelectorAll('input[type="text"]');
// Iterate over each textbox and check if it is empty
for (var i = 0; i<textboxes.length; i++) {
if (textboxes[i].value.trim() === '') {
// Alert the user which textbox is empty
alert('Textbox ' + (i + 1) + ' is empty.');
textboxes[i].focus(); // Optionally set focus to the empty textbox
return false; // Prevent form submission
}
}
RESULT:
Thus, the given program has been executed successfully and output verified.
EX NO:03 Develop a HTML Form, which accepts any Mathematical expression. Write
Date: JavaScript code to Evaluates the expression and display the result.
AIM:
To write a HTML Form, which accepts any Mathematical expression?
ALGORITHM:
Step1: Start the program
Step2: The form contains a single text input field where users can enter their
Mathematical expression
Step 4: The evaluateExpression function retrieves the expression from the input field.
<!DOCTYPE html>
<head>
<title>Mathematical Expression Evaluator</title>
<script>
function evaluateExpression() {
// Get the input value
var expression = document.getElementById('expression').value;
try {
// Evaluate the expression and display the result
var result = eval(expression);
document.getElementById('result').textContent = 'Result: ' + result;
} catch (e) {
// Handle any errors that occur during evaluation
document.getElementById('result').textContent = 'Error: Invalid expression';
}
}
</script>
</head>
<body>
<h1>Mathematical Expression Evaluator</h1>
<form id="expressionForm" onsubmit="event.preventDefault(); evaluateExpression();">
<label for="expression">Enter a mathematical expression:</label><br>
<input type="text" id="expression" name="expression" placeholder="e.g., 2 + 3 * (5 -
2)"><br><br>
<input type="submit" value="Evaluate">
</form>
<p id="result"></p>
</body>
</html>
OUTPUT
RESULT:
Thus, the given program has been executed successfully and output verified.
EX NO:04 Create a page with dynamic effects. Write the code to include layers and
Date: basic animation.
AIM:
To write a HTML Form, which accepts any Mathematical expression.
ALGORITHM:
Step1: Start the program
Step2: The HTML includes a container with three layers: layer1, layer2, and layer.
The layer1 and layer2 layers are for background effects, while layer3
Contains the content and the button.
Step3: Animations: fade-in animation is applied to the heading to make it fade in when
the page loads. Slide In animation is defined for use when the button is clicked
Step4: Button Hover Effect: A simple scale transform is applied to the button on hover
to make it more interactive.
Step5: When the button is clicked, the heading (<h1>) is animated with a slideIn effect.
the background color of layer2 is changed to add a dynamic effect.
Step6: This setup creates a visually appealing page with layered effects and animations.
Step7: stop of the program
PROGRAM
<!DOCTYPE html>
<head>
<title>Dynamic Effects Page</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
overflow: hidden;
}
.layer {
position: absolute;
width: 200px;
height: 200px;
background-color: #3498db;
border-radius: 50%;
animation: move 5s linear infinite alternate;
}
.layer:nth-child(2) {
background-color: #e74c3c;
height: 150px;
width: 150px;
animation-duration: 3s;
}
.layer:nth-child(3) {
background-color: #2ecc71;
width: 100px;
height: 100px;
animation-duration: 7s;
}
@keyframes move {
from {
transform: translateY(0);
}
to {
transform: translateY(200px);
}
}
</style>
</head>
<body>
<div class="layer" style="top: 50px; left: 50px;"></div>
<div class="layer" style="top: 150px; left: 250px;"></div>
<div class="layer" style="top: 300px; left: 150px;"></div>
<script>
// JavaScript code for additional dynamic effects (optional)
</script>
</body>
</html>
OUTPUT
RESULT:
Thus, the given program has been executed successfully and output verified.
EX NO:05 Write a JavaScript code to find the sum of N natural Numbers. (Use user-
Date: defined function)
Aim:
To write a JavaScript code to find the sum of N natural Numbers.
Algorithm:
Step 1: start the program
Step 2:A JavaScript code to find the sum of N natural Numbers. (Use user-defined
function.
Step 4: calculateSum (): This function retrieves the value from the input field, validates
Step 5: The form’s onsubmit event is overridden to prevent the default form submission
(Which would reload the page)? Instead, it calls calculate Sum () to perform the
Step 6: HTML code into a file and open it in a web browser. Enter a positive integer in
the input field and click "Calculate" to see the sum of the first N natural
Numbers
<!DOCTYPE html>
<head>
<script>
// User-defined function to calculate the sum of N natural numbers
function sumOfNaturalNumbers(n) {
if (n <= 0) {
return 0; // If n is less than or equal to 0, return 0 (assuming natural numbers
are positive integers)
}
return (n * (n + 1)) / 2;
}
// Function to handle form submission and display the result
function calculateSum() {
var n = parseInt(document.getElementById('number').value);
if (isNaN(n) || n <= 0) {
document.getElementById('result').textContent = 'Please enter a positive integer.';
} else {
var sum = sumOfNaturalNumbers(n);
document.getElementById('result').textContent = 'The sum of the first ' + n + ' natural
numbers is: ' + sum;
}
}
</script>
</head>
<body>
<h1>Calculate Sum of N Natural Numbers</h1>
<form onsubmit="event.preventDefault(); calculateSum();">
<label for="number">Enter a positive integer (N):</label>
<input type="number" id="number" name="number" min="1" required>
<input type="submit" value="Calculate">
</form>
<p id="result"></p>
</body>
</html>
OUTPUT
RESULT:
Thus, the given program has been executed successfully and output verified.
EX NO:06 Write a JavaScript code block using arrays and generate the current date
in words, this should include the day, month and year
Date:
AIM:
To write a JavaScript code blocks using arrays and generate the current date in words
ALGORITHM:
Step1: start the program
Step 2:Month Names Array: The month’s array maps month numbers (0 to 11)
Step 3: Getting Current Date:new Date() creates a new Date object representing
the current date and time.getDate() extracts the day of the month.
Step 4: GetMonth() extracts the month number (0 for January, 1 for February, etc.),
Which is then used to access the month name from the months array.getFullYear()
Step 5:Formatting the Date: The date is formatted as "day month year", e.g., "29 August
2024".
Step 6: Displaying the Date: The dateInWords is set as the content of the <p> element
<!DOCTYPE html>
<head>
<title>Current Date in Words</title>
<script>
// Function to get the current date in words
function getCurrentDateInWords() {
// Array to map month numbers to month names
const months = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
// Create a new Date object for the current date
const now = new Date();
// Extract day, month, and year
const day = now.getDate();
const month = months[now.getMonth()]; // Get month name from the array
const year = now.getFullYear();
// Format date in words
const dateInWords = `${day} ${month} ${year}`;
// Display the result
document.getElementById('dateInWords').textContent = dateInWords;
}
// Call the function to display the current date in words when the page loads
window.onload = getCurrentDateInWords;
</script>
</head>
<body>
<h1>Current Date in Words</h1>
<p id="dateInWords"></p>
</body>
</html>
OUTPUT
RESULT:
Thus, the given program has been executed successfully and output verified.
EX NO:07 Create a form for Student information. Write JavaScript code to find
Date: Total, Average, Result and Grade
Aim:
To write a form for Student information. Write JavaScript code to find Total,
Average, Result and Grade
Algorithm:
Step1: Start the program
Step 2: The form includes three input fields for scores in three subjects.
Step 3: Get Input Values: Retrieve values from the input fields and convert them to
floats.
Calculate Average: Divide the total by the number of subjects (3 in this case).
Step 4: Determine Result and Grade: If any subject score is below 40,
Step 6: Display Results: Update the content of <p> elements to show the total, average,
<!DOCTYPE html>
<head>
<title>Student Information Form</title>
<link rel="stylesheet" href="styles.css">
<script>
// Function to calculate total, average, result, and grade
function calculateResults() {
// Get input values
var subject1 = parseFloat(document.getElementById('subject1').value);
var subject2 = parseFloat(document.getElementById('subject2').value);
var subject3 = parseFloat(document.getElementById('subject3').value);
// Calculate total
var total = subject1 + subject2 + subject3;
// Calculate average
var average = total / 3;
<h2>Results</h2>
<p id="total"></p>
<p id="average"></p>
<p id="result"></p>
<p id="grade"></p>
</body>
</html>
OUTPUT
RESULT:
Thus, the given program has been executed successfully and output verified.
EX NO:08 Create a form for Employee information. Write JavaScript code to find
DA, HRA, PF, TAX, Gross pay, Deduction and Net pay.
Date:
AIM:
Write a form for Employee information. Write JavaScript code to find DA, HRA,
PF, TAX, Gross pay, Deduction and Net pay
ALGORITHM:
Step1: Start the Program
the default form submission and call the calculateSalary function instead.
Step 3: Retrieve Input: Gets the Basic Salary from the input field.
Step 4: DA: 10% of Basic Salary, HRA: 15% of Basic Salary, PF: 12% of Basic Salary.
Step 5: Gross Pay: Sum of Basic Salary, DA, and HRA. Tax: 5% of Gross
Pay, Deduction: Sum of PF and Tax, Net Pay: Gross Pay minus Deduction
Step 6: Display Results: Updates the content of <p> elements to show the calculated
Values
<!DOCTYPE html>
<head>
<title>Employee Salary Calculation</title>
<link rel="stylesheet" href="styles.css">
<script>
// Function to calculate DA, HRA, PF, TAX, Gross Pay, Deduction, and Net Pay
function calculateSalary() {
// Get input value
var basicSalary = parseFloat(document.getElementById('basicSalary').value);
// Check if the basic salary is a positive number
if (isNaN(basicSalary) || basicSalary<= 0) {
alert('Please enter a valid positive number for Basic Salary.');
return;
}
// Constants for calculations
var daRate = 0.10; // DA as 10% of Basic Salary
var hraRate = 0.15; // HRA as 15% of Basic Salary
var pfRate = 0.12; // PF as 12% of Basic Salary
var taxRate = 0.05; // TAX as 5% of Gross Pay
// Display results
document.getElementById('da').textContent = 'DA: ₹' + da.toFixed(2);
document.getElementById('hra').textContent = 'HRA: ₹' + hra.toFixed(2);
document.getElementById('pf').textContent = 'PF: ₹' + pf.toFixed(2);
document.getElementById('tax').textContent = 'TAX: ₹' + tax.toFixed(2);
document.getElementById('grossPay').textContent = 'Gross Pay: ₹' + grossPay.toFixed(2);
document.getElementById('deduction').textContent = 'Total Deduction: ₹' +
deduction.toFixed(2);
document.getElementById('netPay').textContent = 'Net Pay: ₹' + netPay.toFixed(2);
}
</script>
</head>
<body>
<h1>Employee Salary Calculation</h1>
<form onsubmit="event.preventDefault(); calculateSalary();">
<label for="basicSalary">Enter Basic Salary (₹):</label>
<input type="number" id="basicSalary" name="basicSalary" step="0.01"
required><br><br>
// Display results
document.getElementById('da').textContent = 'DA: ₹' + da.toFixed(2);
document.getElementById('hra').textContent = 'HRA: ₹' + hra.toFixed(2);
document.getElementById('pf').textContent = 'PF: ₹' + pf.toFixed(2);
document.getElementById('tax').textContent = 'TAX: ₹' + tax.toFixed(2);
document.getElementById('grossPay').textContent = 'Gross Pay: ₹' + grossPay.toFixed(2);
document.getElementById('deduction').textContent = 'Total Deduction: ₹' +
deduction.toFixed(2);
document.getElementById('netPay').textContent = 'Net Pay: ₹' + netPay.toFixed(2);
}
</script>
</head>
<body>
<h1>Employee Salary Calculation</h1>
<form onsubmit="event.preventDefault(); calculateSalary();">
<label for="basicSalary">Enter Basic Salary (₹):</label>
<input type="number" id="basicSalary" name="basicSalary" step="0.01"
required><br><br>
<input type="submit" value="Calculate">
</form>
<h2>Salary Breakdown</h2>
<p id="da"></p>
<p id="hra"></p>
<p id="pf"></p>
<p id="tax"></p>
<p id="grossPay"></p>
<p id="deduction"></p>
<p id="netPay"></p>
</body>
</html>
OUTPUT
RESULT:
Thus, the given program has been executed successfully and output verified.
EX NO:09 Create a form consists of a two Multiple choice lists and one single choice
list (The first multiple choice list, displays the Major dishes available.)
Date:
AIM:
Write a form consists of a two Multiple choice lists and one single choice
ALGORITHM:
Step1: Start the Program
Step 2: <select> Element: Contains options for different dishes.<option
Elements: Each option represents a major dish.
Step3: <button>: When clicked, it triggers the displaySelectedDish function to show
the selected dish.
Step 4: JavaScript Function (display Selected Dish):
Retrieves the selected value from the dropdown using value.
Step 5: Maps the selected value to a dish name using an object. Updates the content of
the<div>With the ID result to display the selected dish
Step 6: Styling: Basic styling for form elements, buttons, and result display.
Step 7: stop of the program
PROGRAM
<!DOCTYPE html>
<head>
<title>Major Dishes Selection</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
label {
display: block;
margin-bottom: 5px;
}
select {
padding: 5px;
margin-bottom: 10px;
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
}
button:hover {
background-color: #45a049;
}
.result {
margin-top: 20px;
font-size: 1.2em;
}
</style>
</head>
<body>
<h1>Select Major Dish</h1>
<form id="dishForm">
<label for="dishSelect">Choose a dish:</label>
<select id="dishSelect" name="dishSelect">
<option value="pizza">Pizza</option>
<option value="burger">Burger</option>
<option value="pasta">Pasta</option>
<option value="sushi">Sushi</option>
<option value="tacos">Tacos</option>
</select>
<button type="button" onclick="displaySelectedDish()">Submit</button>
</form>
<div id="result" class="result"></div>
<script>
function displaySelectedDish() {
// Get the selected value from the dropdown
var selectedDish = document.getElementById('dishSelect').value;
// Map the values to dish names
var dishNames = {
pizza: 'Pizza',
burger: 'Burger',
pasta: 'Pasta',
sushi: 'Sushi',
tacos: 'Tacos'
};
RESULT:
Thus, the given program has been executed successfully and output verified.