WP Lab Manual List
WP Lab Manual List
if (isValid) {
document.getElementById("result1").innerHTML += "Email is valid.";
} else {
document.getElementById("result1").innerHTML += "Email is invalid.";
}
}
functionvalidatePhoneNumber() {
varPh_number = document.getElementById("ph_no").value;
if (Ph_number.length ==10)
{
document.getElementById("result2").innerHTML += "Phone number is valid.";
}
else
{
document.getElementById("result2").innerHTML += "Phone number is invalid.";
}
}
</script>
</head>
<body>
<form name="myForm"onsubmit="return check()">
Email: <input type="text" id="email" name="Email"/>
Phone_Number:<input type="text" id="ph_no" name="Phone_Number"/>
Age: <input type="text" name="Age"/><br/><br/>
<input type="submit" value="Send message"/><br/><br/>
</form>
<p id="result1"></p>
<p id="result2"></p>
</body>
</html>
Output:
Labcycle 2: Develop a HTML Form, which accepts any Mathematical expression. Write JavaScript code to Evaluates the
expression and Displays the result.
<body>
<form name="myForm">
Enter any valid expression: <input type="text" id="expr" /><br /><br />
<input type="button" value="Evaluate"onClick="Evaluate()" /><br /><br />
Result of expression: <input type="text" id="result" /><br /><br />
</form>
</body>
</html>
Output:
Labcycle 3:Create a page with dynamic effects. Write the code to include layers and basic animation.
<script type="text/javascript">
functionmoveImage(layer)
{
var top = window.prompt("Enter top value");
var left = window.prompt("Enter left value");
document.getElementById(layer).style.top =top+'px';
document.getElementById(layer).style.left =left+'px';
}
</script>
</head>
<body>
<div id="layer1"><imgsrc="ball.jpg"onclick="moveImage('layer1')" alt="My Image."/></div>
<div id="layer2"><imgsrc="ball.jpg"onclick="moveImage('layer2')" alt="My Image."/></div>
<div id="layer3"><imgsrc="ball.jpg"onclick="moveImage('layer3')" alt="My Image."/></div>
</body>
</html>
Output:
Labcycle 4: Write a JavaScript code to find the sum of N natural Numbers. (Use userdefined function)
<html>
<head>
<title>JavaScript program to find the Sum of n natural numbers</title>
</head>
<body>
<table>
<tr>
<td> <input type="text" name="a" id="first" placeholder="Enter a number"/> </td>
</tr>
<tr>
<td> <button onclick="sum ()">Submit</button></td>
</tr>
</table>
<div id="num"></div>
</body>
<script type="text/javascript">
function sum()
{
var n,i, sum = 0;
n = parseInt(document.getElementById ("first").value);
for (i = 1; i<= n; i++)
{
sum = sum+i;
}
document.getElementById ("num").innerHTML="Sum of "+n+ " natural numbers is :"+sum;
}
</script>
</html>
Output:
Labcycle 5: Write a JavaScript code block using arrays and generate the current date in words, this should include the
day, month and year.
var months = [ "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" ,
"October" , "November" , "December" ];
if (currYear == 2023)
alert ("Today's Date is : " + days [ currDate - 1 ] + "" + months [ currMonth ] + "" + year );
else
alert ("Today's Date is : " + days [ currDate - 1 ] + "" + months [ currMonth ] + "" + currYear );
</script>
</head>
<body>
</body>
</html>
Output:
Labcycle 6: Create a form for Student information. Write JavaScript code to find Total, Average, Result and Grade.
<body>
<form>
<table border="5">
<tr>
<th align="center"colspan="2">Student Details</th>
</tr>
<tr>
<td>Student Name: </td>
<td><input type="text" id="name" /></td>
</tr>
<tr>
<td>Student Class: </td>
<td><input type="text" id="class" /></td>
</tr>
<tr>
<td>Student Marks1: </td>
<td><input type="number" id="sub1" /></td>
</tr>
<tr>
<td>Student Marks2: </td>
<td><input type="number" id="sub2" /></td>
</tr>
<tr>
<td>Student Marks3: </td>
<td><input type="number" id="sub3" /></td>
</tr>
</table>
<input type="button" value="View Results"onClick="showResult()" />
</form>
</body>
</html>
Output:
Labcycle 7: Create a form for Employee information. Write JavaScript code to find DA, HRA, PF, TAX, Gross pay,
Deduction and Net pay.
<body>
<form>
<table border="5">
<tr>
<th> Employee Details </th>
</tr>
<tr>
<th> Employee Name: </th>
<td><input type="text" id="empname" /></td>
</tr>
<tr>
<th> Employee No: </th>
<td><input type="text" id="empno" /></td>
</tr>
<tr>
<th> Basic Pay: </th>
<td><input type="number" id="basic" /></td>
</tr>
</table>
<br /><input type="button" value="Show Salary Details"onClick="showSalary()" />
</form>
</body>
</html>
Output:
Labcycle 8: Write a program in PHP to change background color based on day of the week
using if else if statements and using arrays .
<?php
$dayColors = [
'Sunday'=>'#ffcccb',
'Monday'=>'#ffebcd',
'Tuesday'=>'#add8e6',
'Wednesday' =>'#98fb98',
'Thursday'=>'#f0e68c',
'Friday'=>'#dda0dd',
'Saturday'=>'#c0c0c0'
];
$currentDay =date('l');
$backgroundColor ='#ffffff';
if (array_key_exists($currentDay, $dayColors))
{
$backgroundColor = $dayColors[$currentDay];
}
?>
<html>
<head>
<title> Background Color based on the day of the week </title>
<style>
body {
background-color:<?php echo $backgroundColor; ?>;
}
</style>
</head>
<body>
<h1> welcome! today is <?php echo $currentDay; ?></h1>
</body>
</html>
Labcycle 9: Write a simple program in PHP for i) generating Prime number ii) generate
Fibonacci series.
<?php
functionisPrime($num) {
if($num <=1)
{
return false;
}
for ($i=2;$i<=sqrt($num);$i++)
{
if($num % $i == 0)
{
return false;
}
}
return true;
}
functiongeneratePrimes($n)
{
$primeNumbers = [];
$count = 0;
$i =2;
functiongenerateFibonacci($n) {
$fibonacciSeries=[];
$first = 0;
$second = 1;
$fibonacciSeries[] = $first;
$fibonacciSeries[] = $second;
for($i=2;$i<$n; $i++) {
$next = $first + $second;
$fibonacciSeries[] = $next;
$first = $second;
$second = $next;
}
return $fibonacciSeries;
}
$numberOfPrimes = 50;
$numberOfTerms = 50;
$primes = generatePrimes($numberOfPrimes);
$fibonacci = generateFibonacci ($numberOfTerms);
echo"Prime numbers:";
echo"<pre>".print_r($primes,true). "</pre>";
echo"Fibonacci series:";
echo"<pre>".print_r($fibonacci, true). "</pre>";
?>
Labcycle 10: Write a PHP program to remove duplicates from a sorted list
<?php
functionremove_duplicates_list($list1) {
$nums_unique = array_values(array_unique($list1));
return $nums_unique ;
$nums = array(1,1,2,2,3,4,5,5);
echo"<pre>".print_r($nums,true)."</pre>";
echo"<pre>".print_r(remove_duplicates_list($nums), true)."</pre>";
?>
Labcycle 11: Write a PHP Script to print the following pattern on the Screen:
*****
****
***
**
*
<?php
$rows = 5;
for($i=$rows; $i>=1;$i--) {
echo" ";
for($k=1;$k<=$i; $k++) {
echo"*";
echo"<br>";
?>
Labcycle 12: Write a simple program in PHP for Searching of data by different criteria.
<?php
$users=[ ['id' => 1, 'name' =>'Anjali', 'age' => 20, 'email' =>'anjali@example.com'],
['id' => 2, 'name' =>'Neha', 'age' => 19, 'email' =>'nena@example.com'],
['id' => 3, 'name' =>'Madhu', 'age' => 22, 'email' =>'madhu@example.com'],
['id' => 4, 'name' =>'Vinay', 'age' => 21, 'email' =>'vinay@example.com'],
];
?>
Labcycle 15: Write a program in PHP to read and write file using form control.
<!DOCTYPE html>
<html>
<head>
<title> Read and Write File </title>
</head>
<body>
<h2>Write to File </h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
method="post">
<textarea name="content" rows="5" cols="40" placeholder="Enter text to write"></textarea><br><br>
<input type="submit" name="write" value="write to File">
</form>
<hr>
<h2>Read from File </h2>
<?php
$file='data.txt';
if($_SERVER["REQUEST_METHOD"] == "POST"&&isset($_POST['write'])) {
$content = $_POST['content'];
file_put_contents($file, $content, FILE_APPEND|LOCK_EX);
echo"content written to file successfully!";
}
if(file_exists($file)) {
$content = file_get_contents($file);
echo"<pre>$content </pre>";
}
else
{
echo"file not found!";
}
?>
</body>
</html>
Labcycle 17: Write a program in PHP to Validate Input
<?php
// Function to validate an email address
functionvalidateEmail($email) {
// Define a regular expression for a valid email address
$emailRegex = '/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/';
// Use the preg_match function to check if the email matches the pattern
returnpreg_match($emailRegex, $email);
}
<!DOCTYPE html>
<html lang="en">
<head>
<metacharset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email Validation</title>
</head>
<body>
<h2>Enter Your Email </h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<label for="email">Email:</label>
<input type="text" id="email" name="email" required>
<br>
<input type="submit" value="Submit">
</form>
/body>
</html>
Labcycle 18: Write a program in PHP for setting and retrieving a cookie
<?php
$cookie_name = "UserID";
$cookie_value = "A1B234C";
$expiration_time = time() + (24 * 3600);
index.php
<!DOCTYPE html>
<html>
<head>
<title> KLE S Nijalingappa College</title>
<style>
body {
font-family: Arial, sans-serif;
}
header{
background-color: #f8f9fa;
padding: 20px;
text-align: center;
}
nav {
margin: 20px 0;
text-align: center;
}
nav a {
margin: 0 15px;
}
</style>
</head>
<body>
<header>
<imgsrc ="logo.jpg" alt="KLE society S Nijalingappa College" width="100">
<h1> KLE Society's S Nijalingappa College </h1>
<p> 642/1, 12th Main Rd, Basaveshwar Nagar, </p>
<p>Rajajinagar, Bengaluru, Karnataka 560010 </p>
</header>
<nav>
<a href="index.php">Home</a>
<a href="about.html">About us</a>
<a href="Courses.php">Courses</a>
<a href="Contact.html">Contact Us</a>
</nav>
<main>
<h2> Welcome to KLE College Rajajinagar</h2>
<p>We provide best education on computer applications courses </p>
</main>
</body>
</html>
about.html
<!DOCTYPE html>
<html>
<head>
<title> About us - KLE Society S Nijalingappa college </title>
</head>
<body>
<h1>About us </h1>
<p> University K.L.E. Society S. Nijalingappa College, established in the year 1963, is one of the
premier institutions of K.L.E Society. It made a humble beginning in a rented building
on Mahatma Gandhi Road, near Mayo Hall, as a Science College. It was shifted to the present
premises in 1966. The founder Principal Dr.V.G. Nelivigi laid a firm foundation
for the college and was responsible for development of the college,
by its inclusion under 2(f) and 12(B) of UGC.</p>
</body>
</html>
Courses.php:
<!DOCTYPE html>
<html>
<head>
<title> Courses - KLE College Rajajinagar</title>
</head>
<body>
<h1> Courses </h1>
<h2> BCA </h2>
<h2> MCA </h2>
</body>
</html>
Contact.html:
<!DOCTYPE html>
<html>
<head>
<title> Contact Us - KLE College Rajajinagar</title>
</head>
<body>
<h1> Contact Us </h1>
<p>KLE Society S Nijalingappa College </p>
<p>#1040, II Block, Rajajinagar,</p>
<p>Bengaluru-560010</p>
</body>
</html>
Labcycle 20: Write a program in PHP for exception handling for i) divide by zero ii) Checking
date format.
<?php
try {
$numerator = 10;
$denominator = 5;
if($denominator ===0) {
throw new Exception ("division by zero error");
}
$result = $numerator / $denominator;
echo"Result of division :" . $result ."<br>";
$dateString = '2023-12-25';
$dateFormat = 'Y-m-d';