0% found this document useful (0 votes)
6 views5 pages

All Program File

The document outlines various programming tasks involving HTML forms, JavaScript, and PHP. It includes creating forms for student and employee information, validating inputs, and performing calculations such as evaluating mathematical expressions and salary breakdowns. Additionally, it covers generating prime numbers, Fibonacci series, and managing cookies and file operations in PHP.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

All Program File

The document outlines various programming tasks involving HTML forms, JavaScript, and PHP. It includes creating forms for student and employee information, validating inputs, and performing calculations such as evaluating mathematical expressions and salary breakdowns. Additionally, it covers generating prime numbers, Fibonacci series, and managing cookies and file operations in PHP.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. Create a form with the elements of 2.

Develop an HTML Form, which accepts any


Textboxes, Radio buttons, Checkboxes, and Mathematical expression. Write JavaScript code to . 3. Create a page with dynamic effects. Write the code to include
so on. Write JavaScript code to validate the Evaluate the expression and Display the result. layers and basic animation
<body bgcolor="Pink">
format in email, and mobile number in 10
<form name="myForm" <html>
characters, If a textbox has been left empty, <html>
onsubmit="return validate()"> <head>
popup an alert indicating when email, mobile
<h1>Student Information <head><script>
number and textbox has been left empty <title>Basic Animation</title>
Form</h1> function calc(){
<style>
Name: <input type="text" try{ [Link] = eval([Link]); }
<html> img{position:absolute;cursor:pointer;}
<head> name="Name"><br><br> catch{ alert("Invalid expression!"); }
#i1{top:80px;left:150px;}
<title>Form Validation</title> Password: <input } #i2{top:130px;left:450px;}
<script> type="password" </script></head> #i3{top:180px;left:750px;}
function validate() { name="Password"><br><br>
</style>
let f = [Link]; Address: <textarea <body bgcolor="olive">
name="Address"></textarea>
<h2>Expression Evaluator</h2> <script>
// Check empty fields <br><br>
function move(id){
let empty = [...[Link]].filter(e => Sex:
Expression: <input id="expr"> let t = prompt("Enter Top:"), l = prompt("Enter Left:");
![Link]).map(e => [Link]); <input type="radio"
name="Gender" value="M">
<button onclick="calc()">=</button><br><br> let e = [Link](id);
if ([Link]) return alert("Empty
Male [Link] = t+"px";
fields:\n" + [Link](", ")), false;
<input type="radio" Result: <input id="result"> [Link] = l+"px";
name="Gender" value="F"> </body> }
// Mobile check
if ([Link] != 10) Female </html> </script>
return alert("Enter a 10 digit mobile <br><br> </head>
number!"), false; Student <input type="checkbox"
name="Student" checked><br> <body bgcolor="Tan">
[Link] a JavaScript code to find the sum of
// Email check <br> <h3>Basic Animation</h3>
N natural Numbers. (Use userdefined
let e = [Link], at = [Link]("@"), Email: <input type="text"
dot = [Link]("."); name="Email"><br><br>
function) <img id="i1" src="[Link]" onclick="move('i1')">
if (at < 1 || dot < at + 2 || dot + 2 >= Mobile: <input type="number" <img id="i2" src="[Link]" onclick="move('i2')">
[Link]) name="Phno"><br><br> <html><body bgcolor="LightYellow"> <img id="i3" src="[Link]" onclick="move('i3')">
return alert("Invalid Email ID!"), false; <input type="submit" <h3>Sum of N Natural Numbers</h3>
value="Submit"> <button onclick="let n=+prompt('Enter </body>
return true; </form> </html>
N:');alert('Sum: '+(n*(n+1)/2))">Find
} </body>
</script> </html> Sum</button>
</head> </body></html>
[Link] a JavaScript code block using arrays and [Link] a form for Student information. Write JavaScript 7. Create a form for Employee information. Write JavaScript code to find DA, HRA,
generate the current date in words, this should include code to find Total, Average, Result and Grade. PF, TAX, Gross pay, Deduction and Net pay

the day, month and year.


<html><body bgcolor="beige">
<html><body bgcolor="peachpuff">
<html><body bgcolor="teal"> <table border="5"> <table border="5">
<script> <tr><th colspan=2>Student Details</th></tr> <tr><th colspan=2>Employee Details</th></tr>
let d=new Date(), <tr><td>Name</td><td><input id="n"></td></tr> <tr><td>Name</td><td><input id="n"></td></tr>
day=[Link](), <tr><td>Class</td><td><input id="c"></td></tr> <tr><td>Number</td><td><input id="no"></td></tr>
<tr><td>Basic Pay</td><td><input id="b"></td></tr>
month=[Link]('default',{month:'long'}), <tr><td>Sub1</td><td><input id="s1"></td></tr>
</table><br>
year=[Link]()==2023?"Two Thousand Twenty <tr><td>Sub2</td><td><input id="s2"></td></tr>
Three":[Link](), <tr><td>Sub3</td><td><input id="s3"></td></tr> <button onclick="
w= </table><br> let basic=+[Link],
["Zero","First","Second","Third","Fourth","Fifth","Sixth" hra=basic*0.4,
<button onclick=" da=basic*0.6,
,"Seventh","Eighth","Ninth",
let t=+[Link]+ +[Link]+ +[Link], gross=basic+hra+da,
"Tenth","Eleventh","Twelfth","Thirteenth","Fourteenth"," pf=gross*0.13,
Fifteenth","Sixteenth","Seventeenth", a=t/3,
tax=gross*0.2,
"Eighteenth","Nineteenth","Twenty","Twenty g=a>=60?'A':a>=50?'B':a>=40?'C':'D', ded=pf+tax,
One","Twenty Two","Twenty Three","Twenty Four", r=a>=60?'First Class':a>=50?'Second Class':a>=40?'Third net=gross-ded;
"Twenty Five","Twenty Six","Twenty Seven","Twenty Class':'Fail';
[Link]= [Link] =
Eight","Twenty Nine","Thirty","Thirty One"];
'<h2>Results</h2>'+ `<table border=5>
<tr><th colspan=2>Employee Salary Breakup</th></tr>
alert(`Today's Date is : ${w[day]} ${month} ${year}`); 'Name: '+[Link]+'<br><br>'+
<tr><td>Name</td><td>${[Link]}</td></tr>
</script> 'Class: '+[Link]+'<br><br>'+ <tr><td>Number</td><td>${[Link]}</td></tr>
</body></html> 'Total: '+t+'<br><br>'+ <tr><td>Basic Pay</td><td>${basic}</td></tr>
'Average: '+a+'<br><br>'+ <tr><td>HRA (40%)</td><td>${hra}</td></tr>
'Grade: '+g+'<br><br>'+ <tr><td>DA (60%)</td><td>${da}</td></tr>
'Result: '+r; <tr><td>Gross</td><td>${gross}</td></tr>
<tr><td>PF (13%)</td><td>${pf}</td></tr>
">View Results</button>
<tr><td>Tax (20%)</td><td>${tax}</td></tr>
<tr><td>Total Deductions</td><td>${ded}</td></tr>
</body></html> <tr><td><b>Net Salary</b></td><td><b>${net}</b></td></tr>
</table>`;
">Show Salary Details</button>

</body></html>
[Link] a PHP program to remove
8. Write a program in PHP to change background
duplicates from a sorted list.
color based on day of the week using if else if
statements and using arrays .
<html><body bgcolor="lightcoral"
style="text-align:center;font-
<!DOCTYPE html>
[Link] a simple program in PHP for i) family:Arial;"> 11. Write a PHP Script to
<html>
<?php generating Prime number ii) generate print the pattern on the
$colors = [ Fibonacci series. <?php Screen.
$orig = [1,2,2,3,4,4,4,5,6,6];
"Sunday"=>"teal","Monday"=>"cyan","Tuesday"=>
<html><body bgcolor="cyan" style="text- $unique = <html><body
"turquoise",
"Wednesday"=>"lightblue","Thursday"=>"orange", align:center;font-family:Arial;"> array_values(array_unique($orig)); bgcolor="plum" style="text-
"Friday"=>"tomato","Saturday"=>"olive" <?php align:center;font-
]; echo "<h3>Prime numbers up to 100:</h3>"; echo "<p>Original List: ".implode(", family:Arial;">
$day = date("l");
for($i=2;$i<=100;$i++){
$bg = $colors[$day]; ",$orig)."</p>";
echo "<body style='background:$bg; text- for($p=1,$j=2;$j*$j<=$i;$j++) if($i%$j==0) <?php
echo "<p>Unique List: ".implode(",
align:center; font-family:Arial;'>"; {$p=0;break;} for($i=1;$i<=5;$i++) echo
",$unique)."</p>";
?> if($p) echo "$i ";
?> str_repeat("$ ",$i)."<br>";
<h2>Happy <?= $day ?>!</h2>
}
<p>Today's background color is:
<span style="background:<?= $bg ?>; </body></html> echo "<br><br><br>";
padding:5px;"><?= $bg ?></span> echo "<h3>Fibonacci series (20 terms):
</p> </h3>"; for($i=6;$i>=1;$i--) echo
</body> $f=[0,1];
</html> str_repeat("* ",$i)."<br>";
for($i=2;$i<20;$i++) $f[$i]=$f[$i-1]+$f[$i-2]; ?>
echo implode(", ",$f);
?> </body></html>
</body></html>
12. Write a simple program in PHP for Searching of data by different .15. Write a program in PHP to read and
criteria. write file using form control. 16. Write a program in PHP to add, update and delete
<html>
<body bgcolor="rosybrown" style="text-align:center;font-family:Arial;">
using student database.
<!DOCTYPE html>
<?php <html> <html><body bgcolor="cadetblue">
$data = [ <body> <?php
['name'=>'John','age'=>25,'id'=>1,'sal'=>25000], $conn = new mysqli("localhost","root","","studentdb");
['name'=>'Jane','age'=>30,'id'=>2,'sal'=>35000], if($conn->connect_error) die("DB Error");
<h2>Write to File</h2>
['name'=>'Bob','age'=>22,'id'=>3,'sal'=>45000],
['name'=>'Alice','age'=>28,'id'=>4,'sal'=>65000]
<form method="post">
<textarea name="content" rows="5" echo ($conn->query("INSERT INTO
];
cols="40"></textarea><br><br> students(name,age,grade) VALUES('Akshata',34,'A+')"))
if($_POST){ ? "New record added successfully.<br><br><br>"
<input type="submit" name="write"
$c=$_POST['criteria']; : "Add Error<br>";
value="Write to File">
$v=$_POST['search'];
</form>
$found=false; echo ($conn->query("UPDATE students SET age=33 WHERE
<hr>
name='Akshata'"))
foreach($data as $d){ ? "Record updated successfully.<br><br><br>"
if($d[$c]==$v){ <?php : "Update Error<br>";
echo "<p>Name:{$d['name']}, Age:{$d['age']}, ID:{$d['id']}, Sal:{$d['sal']} $file = "[Link]";
</p>";
$found=true; echo ($conn->query("DELETE FROM students WHERE
} if(isset($_POST['write'])){ name='Akshata'"))
} file_put_contents($file, ? "Record deleted successfully.<br><br><br>"
$_POST['content'], FILE_APPEND); : "Delete Error<br>";
if(!$found) echo "<p>No matching results found.</p>"; echo "Content written to file
} $conn->close();
successfully!<br><br>";
?>
} ?>
</body></html>
<form method="post" style="margin-top:20px;">
<select name="criteria"> echo file_exists($file)
<option value="name">Name</option> ? "<pre>".file_get_contents($file)."
<option value="age">Age</option> </pre>"
</select>
: "File not found!"; CREATE TABLE students (
<input name="search" placeholder="Enter value">
<button>Search</button> ?> id INT AUTO_INCREMENT PRIMARY KEY,
</form> name VARCHAR(100) NOT NULL,
age INT NOT NULL,
</body>
grade VARCHAR(10) NOT NULL
</body> </html> );
</html>
17. Write a program in PHP to Validate Input.

<!DOCTYPE html>

18. Write a program in PHP for setting


<html>
<body bgcolor="lavender">
and retrieving a cookie.
<?php
$err = $user = "";
<!DOCTYPE html>
<html>
if($_SERVER["REQUEST_METHOD"] == "POST"){
$user = $_POST["username"] ?? ""; // SAFE — avoids warning
<body bgcolor="gold">
if($user == ""){
$err = "Username is required";
} elseif(!preg_match("/^[a-zA-Z ]+$/", $user)){ <?php
setcookie("UserID","Hello_Students!!",
$err = "Only letters and white space allowed";
}
} time()+86400, "/");
echo "Cookie 'UserID' is set.<br><br>
?>

<h2>Validate Input: Username</h2> <br>";


<form method="post">
Username: <input type="text" name="username"> echo isset($_COOKIE["UserID"])
? "Value of cookie 'UserID' is:
<span>* <?php echo $err; ?></span><br><br>
<input type="submit" value="Submit">
</form> ".$_COOKIE["UserID"]
<?php
: "Cookie named 'UserID' is not set.";
if($user && !$err){ ?>
echo "<h3>Entered Username:</h3>$user";
}
?> </body>
</body>
</html>
</html>

You might also like