php practical exam slips
Savitribai Phule Pune University T.Y.B.Sc. (CS)
Sem-VI(2019 Pattern)
UniversityPractical Examination, May 2023
CS-368- Web Technology II & Data Analytics
slip 1
Q. 1) Write a PHP script to keep track of number of times the web page has been accessed (Use Session Tracking)
<html>
<head>
<title> Number of times the web page has been viited.</title>
</head>
<body>
<?php
session_start();
if(isset($_SESSION['count']))
$_SESSION['count']=$_SESSION['count']+1;
else
$_SESSION['count']=1;
echo "<h3>This page is accessed</h3>".$_SESSION['count'];
?>
</body>
</html>
OUTPUT:
This page is accessed
117
slip 2
Q. 1Write a PHP script to change the preferences of your web page like font style, font size, font color, background color using cookie. Display selected setting on next web page and actual implementation (with new settings) on third page (Use Cookies).
<html>
<body>
<form action="Q2webpage_font.php" method="get">
<center>
<b>Select font style :</b>
<input type="text" name="fstyle"> <br>
<b>Enter font size : </b>
<input type="text" name="fsize"><br>
<b>Enter font color : </b>
<input type="text" name="fcolor"><br>
<b>Enter background color :</b>
<input type="text" name="fbgcolor"><br>
<input type=submit value="Next">
</center>
</form>
</body>
</html>
<?php
echo "style is ".$_GET['fstyle']."<br>size is ".$_GET['fsize']."<br>color is ".$_GET['fcolor']."<br>Background color is ".$_GET['fbgcolor'];
setcookie("set1",$_GET['fstyle'],time()+3600);
setcookie("set2",$_GET['fsize'],time()+3600);
setcookie("set3",$_GET['fcolor'],time()+3600);
setcookie("set4",$_GET['fbgcolor'],time()+3600);
?>
<html>
<body>
<form action="Q2font_display.php">
<input type=submit value=OK>
</form>
</body>
</html>
Q2font_display.php
<?php
$style = $_COOKIE['set1'];
$size = $_COOKIE['set2'];
$color = $_COOKIE['set3'];
$b_color = $_COOKIE['set4'];
$msg = "I'm the top of the world...";
echo "<body bgcolor=$b_color>";
echo "<font color=$color size=$size>$msg ";
echo "</font></body>";
?>
slip 3
Q. 1) Write a PHP script to accept username and password. If in the first three chances, username and password entered is correct then display second form with “Welcome message” otherwise display error message. [Use Session]
Q3user_chance.html
<html>
<body>
<form action="Q3user_chance.php" method="POST">
<center>
<b>Enter the username:</b>
<input type="text" name="username"> <br>
<b>Enter font Password : </b>
<input type="text" name="password"><br>
<input type=submit value="Next">
</center>
</form>
</body>
</html>
Q3user_chance.php
<?php
setCookie("setname",$_POST['username'],time()+60*60*1);
setCookie("setpass",$_POST['password'],time()+60*60*1);
?>
<html>
<body>
<form action ="Q3chk_pass.php">
<input type = "submit" name ="submit">
</form>
</body>
</html>
Q3chk_pass.php
<?php
$usr = "swapnil";
$psw = "nil";
$name = $_COOKIE['setname'];
$pass = $_COOKIE['setpass'];
session_start();
// $_SESSION['count2']=0;
if($_SESSION['count2']<3)
{
if (($name == "swapnil" && $pass == "nil"))
{
echo "WELCOME SIR/MAM Ur LOGIN SUCCESSFULLY DONE...";
}
else {
$_SESSION['count2'] = $_SESSION['count2']+1;
echo "incorrect login try again...<BR> U have ".(3 - $_SESSION['count2']). " chances" ;
}
}
else {
echo "More than 3 chances not allow for incorrect login!!!";
}
?>
Enter the username:
Enter font Password :
Enter the username:
Enter font Password :
incorrect login try again...
U have 2 chances
incorrect login try again...
U have 1 chances
incorrect login try again...
U have 0 chances
slip 4
Q. 1) Write a PHP script to accept Employee details (Eno, Ename, Address) on first page. On second page accept earning (Basic, DA, HRA). On third page print Employee information (Eno, Ename, Address, Basic, DA, HRA, Total) [ Use Session]
<html>
<body>
<form action="Q4E_detail.php" method="get">
<center> <h2>Enter Enployee Details :</h2> <br>
<table>
<tr> <td><b>Emp no :</b></td> <td><input type=text name=eno></td> </tr>
<tr> <td><b> Name :</b></td> <td><input type=text name=ename></td> </tr>
<tr> <td><b>Address :</b></td> <td><input type=text name=eaddress></td> </tr>
</table>
<br> <input type=submit value=Show name=submit>
</center>
</form>
</body>
</html>
Q4E_detail.php
<?php
session_start();
$eno = $_GET['eno'];
$ename = $_GET['ename'];
$eadd = $_GET['eaddress'];
$_SESSION['eno'] = $eno;
$_SESSION['ename'] = $ename;
$_SESSION['eadd'] = $eadd;
?>
<html>
<body>
<form action="Q4E_earn.php" method="post">
<center>
<h2>Enter Earnings of Employee:</h2>
<table>
<tr><td>Basic : </td><td><input type="text" name="ebasic"></td><tr>
<tr><td>DA : </td><td><input type="text" name="eda"></td></tr>
<tr><td>HRA : </td><td><input type="text" name="ehra"></td></tr>
<tr><td></td><td><input type="submit" value=Next></td></tr>
</table>
</center>
</form>
</body>
</html>
<?php
session_start();
$basic = $_POST['ebasic'];
$da = $_POST['eda'];
$hra= $_POST['ehra'];
$total = $basic+$da+$hra;
echo "<h3>Employee Details</h3> ";
echo "Name : ".$_SESSION['eno']."<br>";
echo "Address : ".$_SESSION['ename']."<br>";
echo "Class : ".$_SESSION['eadd']."<br><br>";
echo "basic : ".$basic."<br>";
echo "DA : ".$da."<br>";
echo "HRA : ".$hra."<br>";
echo "<h2>Total Of Earnings Is : ".$total."</h2>";
?>
Enter Enployee Details :
| Emp no : | |
| Name : | |
| Address : |
Enter Earnings of Employee:
| Basic : | |
| DA : | |
| HRA : | |
Employee Details
Name : 32
Address : swapnil
Class : wasunde
basic : 100
DA : 300
HRA : 500
Total Of Earnings Is : 900
slip 5
Q. 1) Create XML file named “Item.xml”with item-name, item-rate, item quantity Store the details of 5 Items of different Types
<?xml version = "1.0" encoding ="UTF-8"?>
<Item_Detail>
<item>
<item_name> Redmi note 8 pro </item_name>
<item_rate> 15000 </item_rate>
<item_quantity> 2 </item_quantity>
</item>
<item>
<item_name> Samsung </item_name>
<item_rate> 30000 </item_rate>
<item_quantity> 5 </item_quantity>
</item>
<item>
<item_name> Oppo </item_name>
<item_rate> 45000 </item_rate>
<item_quantity> 3 </item_quantity>
</item>
<item>
<item_name> Apple </item_name>
<item_rate> 100000 </item_rate>
<item_quantity> 1 </item_quantity>
</item>
<item>
<item_name> Iphone </item_name>
<item_rate>500000 </item_rate>
<item_quantity> 1 </item_quantity>
</item>
</Item_Detail>
slip 6
Q. 1) Write PHP script to read “book.xml” file into simpleXML object. Display attributes and elements . ( simple_xml_load_file() function )
<?php
$xmldata = simplexml_load_file("Q6book.xml") or die("Failed to load");
echo "Name Rate Quantity <BR> ";
foreach($xmldata->children() as $book)
{
echo $book->book_name . ", ";
echo $book->book_rate . ", ";
echo $book->book_quantity . "<BR> ";
}
?>
Name Rate Quantity
wings of fire , 5000 , 2
Miracal morning , 500 , 10
101 habits , 1000 , 4
Q7movie.xml
<?xml version="1.0" encoding="UTF-8"?>
<Movie>
<MovieInfo>
<MovieNo>1</MovieNo>
<MovieTitle>Shawshank Redemption</MovieTitle>
<ActorName>Mann </ActorName>
<ReleaseYear>1998</ReleaseYear>
</MovieInfo>
<MovieInfo>
<MovieNo>2</MovieNo>
<MovieTitle>Welcome</MovieTitle>
<ActorName>Akshay </ActorName>
<ReleaseYear>2010</ReleaseYear>
</MovieInfo>
<MovieInfo>
<MovieNo>3</MovieNo>
<MovieTitle>The perfect girl</MovieTitle>
<ActorName>sam</ActorName>
<ReleaseYear>2019</ReleaseYear>
</MovieInfo>
<MovieInfo>
<MovieNo>4</MovieNo>
<MovieTitle>Harry potter</MovieTitle>
<ActorName>Harry</ActorName>
<ReleaseYear>1999</ReleaseYear>
</MovieInfo>
<MovieInfo>
<MovieNo>5</MovieNo>
<MovieTitle>London has fallen</MovieTitle>
<ActorName>gerard buttler</ActorName>
<ReleaseYear>2013</ReleaseYear>
</MovieInfo>
</Movie>
Q7movie.php
Movie Title:
Shawshank Redemption
Welcome
The perfect girl
Harry potter
London has fallen
Movie Name:
Mann
Akshay
sam
Harry
gerard buttler
slip 8
Q. 1) Write a JavaScript to display message ‘Exams are near, have you started preparing for?’ (usealert box ) and Accept any two numbers from user and display addition of two number .(Use Prompt and confirm box
<html>
<head><title>Addition of two numbers</title></head>
<body>
<form>
<h1> Addition of two numbers </h1>
<input type="button" value="Addition" onclick="check()">
</form>
<script type="text/javascript">
function check()
{
var a,b,c;
alert("Exams are near, have you statred for preparing?");
a= parseInt(prompt("Enter first number"));
b= parseInt(prompt("Enter second number"));
c= a+b;
confirm("Addition of two numbers is:-" +c);
}
</script>
</body>
</html>
Addition of two numbers
Exams are near, have you statred for preparing?
Enter first number 2
Enter second number 3
Addition of two numbers is:-5
Membership form
Username:Password:
<html>
<head><title>javascript</title>
<script
type="text/javascript">
function
validate()
{
var user,pass,ans,ch;
ans="true";
user=f1.t1.value;
pass=f1.t2.value;
if(user.length<8||user.length>15||pass.length<6||pass.length>10)
{
alert("user
name having length 8 to 15 and password length is 6 to 10");
ans="false";
}
for(i=0;i<pass.length;i++)
{
ch=pass.charAt(i);
if(ch=="
"||ch=="("||ch==")"||ch=="{"||ch=="}"||ch=="?"||ch=="*"||ch=="."||ch==","
)
{
alert("space
and special symbols are not allowed in password");
ans="false";break;
}
}
for(i=0;i<user.length;i++)
{
ch=user.charAt(i);
if((ch<"a"
|| ch>"z")&&(ch<0 || ch>9))
{
alert("username
contains capital and lower alphabets");
ans="false";
break;
}
}
if(ans=="true")
alert("currect
user name and password");
else
alert("Wrong
user name and password, Re-enter ");
}
</script></head>
<body
bgcolor="yellow">
<h1
align="center">Validation of Password</h1>
<form
name="f1" method="post">
Enter your name:-
<input
type="text" name="t1"><br>
Enter password:-
<input
type="password"
name="t2"><br>
<center><input
type="button" value="validate" onMouseMove="validate()">
<input
type="reset" value="reset"></center>
</form></body></html>
Validation of Password
slip 11
Q. 1) Write a Javascript program to accept name of student, change font color to red, font size to 18 if student name is present otherwise on clicking on empty text box display image which changes its size (Use onblur, onload, onmousehover, onmouseclick, onmouseup)
<html>
<head><title>Test change program</title></head>
<body>
<form name="form">
<h1> to Change text font color </h1>
Enter student name:-
<input type="text" id="demo" name="t1" onblur="check()">
</form>
<script type="text/javascript">
function check()
{
alert("hello");
var a=form.t1.value;
if(a.length==0)
{
var x = document.createElement("IMG");
x.setAttribute("src", "#");
x.setAttribute("width", "100");
x.setAttribute("height", "228");
x.setAttribute("alt", "I'm the top of the world");
document.body.appendChild(x);
}
else
{
document.getElementById("demo").style.color ="blue";
document.getElementById("demo").style.fontSize = "40";
}
}
</script>
</html>
slip 12
Q. 1)Write AJAX program to read contact.dat file and print the contents of the file in a tabular format when the user clicks on print button. Contact.dat file should contain srno, name, residence number, mobile number, Address. [Enter at least 3 record in contact.dat file]
slip 13
Q. 1) Write AJAX program where the user is requested to write his or her name in a text box, and the server keeps sending back responses while the user is typing. If the user name is not entered then the message displayed will be, “Stranger, please tell me your name!”. If the name is Rohit, Virat, Dhoni, Ashwin or Harbhajan , the server responds with “Hello, master !”. If the name is anything else, the message will be “, I don’t know you!”
slip 14
Q. 1) Create TEACHER table as follows TEACHER(tno, tname, qualification, salary). Write Ajax program to select a teachers name and print the selected teachers details
slip 15
Q. 1) Write Ajax program to fetch suggestions when is user is typing in a textbox. (eg like google suggestions. Hint create array of suggestions and matching string will be displayed)
slip 16
Q. 1) Write Ajax program to get book details from XML file when user select a book name. Create XML file for storing details of book(title, author, year, price).
slip 17
Q. 1) Write a Java Script Program to show Hello Good Morning message onload event using alert box and display the Student registration from.
<html>
<head><title>Hello</title></head>
<body
onload="msg()">
<h1
align="center">Student Registration From </h1>
<form
name="f1" method="post">
Name:-
<input type="text"
name="t1"><br>
Adress:-
<textarea rows=3
cols=20></textarea><br>
Gender:-<br>
<input type="radio"
name="r1" value="male">Male <br>
<input type="radio"
name="r1" value="female">Female<br>
Mobile No.
<input type="number"
maxlength=10><br>
Subject:-<br>
<input type="checkbox"
name="c1">Biology<br>
<input type="checkbox"
name="c2">Physics<br>
<input type="checkbox"
name="c3">Chemistry<br>
<input type="checkbox"
name="c4">English<br>
<input type="checkbox"
name="c5">Mathematics<br>
<input
type="submit" value="submit">
<input
type="reset" value="Reset">
</form>
<script
type="text/javascript">
function msg()
{
alert("Hello
Good Morning");
}
</script>
</html>
slip 18
Q. 1) Write a Java Script Program to print Fibonacci numbers on onclick event.
<html>
<head><title>Fibonacci series</title></head>
<body>
<form name="frm1">
<h1> Fibonacci series </h1>
<input type="button" value="Display" onclick="check()">
</form>
<script type="text/javascript">
function check()
{
var a,b,c;
a=0; b=1;
document.write(a + "<br>" + b + "<br>");
for(i=1;i<=10;i++)
{
c=a+b;
document.write(c + "<br>");
a=b;
b=c;
}
}
</script>
</body>
</html>
Fibonacci series
2
3
5
8
13
21
34
55
89
144
slip 19
Q. 1) Write a Java Script Program to validate user name and password on onSubmit event. [
slip 20
Q. 1) create a student.xml file containing at least 5 student informatioon
<?xml version="1.0" encoding="UTF-8"?>
<Student_Detail>
<Student>
<studentno>1</studentno>
<studentname>Swapnil </studentname>
<studentcity>patas </studentcity>
<studentphno>9356111111</studentphno>
</Student>
<Student>
<studentno>2</studentno>
<studentname> Omu</studentname>
<studentcity>Baramati </studentcity>
<studentphno>914599999</studentphno>
</Student>
<Student>
<studentno>3</studentno>
<studentname> Sam</studentname>
<studentcity> Daund </studentcity>
<studentphno>923847933</studentphno>
</Student>
<Student>
<studentno>4</studentno>
<studentcity>Avi </studentcity>
<studentphno>1993843388</studentphno>
</Student>
<Student>
<studentno>5</studentno>
<studentname> Anu</studentname>
<studentcity>supe </studentcity>
<studentphno>2934848484</studentphno>
</Student>
</Student_Detail>
Q. 1)Add a JavaScript File in Codeigniter. The Javascript code should check whether a number is positive or negative.
slip 22
Q. 1)Create a table student having attributes(rollno, name, class). Using codeigniter, connect to the database and insert 5 recodes in it.
slip 23
Q. 1) Create a table student having attributes(rollno, name, class) containing atleast 5 recodes . Using codeigniter, display all its records.
slip 24
Q. 1) Write a PHP script to create student.xml file which contains student roll no, name, address, college and course. Print students detail of specific course in tabular format after accepting course as input.
Q9student.xml
<?xml version="1.0" encoding="UTF-8"?>
<Student_Detail>
<Student>
<studentrnno>1</studentrnno>
<studentname>Swapnil </studentname>
<studentAddress>patas </studentAddress>
<studentCollege>Vidya Pratishthan</studentCollege>
<studentCource> Core Java </studentCource>
</Student>
<Student>
<studentrnno>2</studentrnno>
<studentname>Omu </studentname>
<studentAddress>patas </studentAddress>
<studentCollege>Vidya Pratishthan</studentCollege>
<studentCource> Python </studentCource>
</Student>
<Student>
<studentrnno>3</studentrnno>
<studentname>Avi </studentname>
<studentAddress>Baramati </studentAddress>
<studentCollege>Vidya Pratishthan</studentCollege>
<studentCource> Php wala </studentCource>
</Student>
</Student_Detail>
Q9stud_cource.php
<?php
$doc = new DOMDocument();
$doc->load("Q9student.xml");
$cname = $doc->getElementsByTagName("studentCource");
echo "Cource name of students:<BR>";
foreach($cname as $value)
{
echo "<BR> $value->textContent";
}
?>
Cource name of students:
Core Java
Python
Php wala
slip 25
Q. 1) Write a script to create “cricket.xml” file with multiple elements as shown below:
Q10cricket.xml
<?xml version = "1.0" encoding ="UTF-8" ?>
<CricketTeam>
<Team country="India">
<player>Dhoni</player>
<runs>10000</runs>
<wicket>50</wicket>
</Team>
<Team country="Austrelia">
<player>maxwell</player>
<runs>5000</runs>
<wicket>80</wicket>
</Team>
<Team country="Pakistan">
<player>wasim</player>
<runs>500</runs>
<wicket>100</wicket>
</Team>
</CricketTeam>
<?php
$xml = simplexml_load_file("Q10cricket.xml") or die("Failed to load");
$xmlstring = $xml->asXML();
echo $xmlstring;
?>
slip 26
Q. 1) Create employee table as follows EMP (eno, ename, designation, salary). Write Ajax program to select the employees name and print the selected employee’s details.
slip 27
Q. 1) Create web Application that contains Voters details and check proper validation for (name, age, and nationality), as Name should be in upper case letters only, Age should not be less than 18 yrs and Nationality should be Indian.(use HTML-AJAX-PHP)
slip 28
Q. 1) Write a PHP script using AJAX concept, to check user name and password are valid or Invalid (use database to store user name and password).
slip 29
Q. 1) Write a PHP script for the following: Design a form to accept a number from the user. Perform the operations and show the results. 1) Fibonacci Series. 2) To find sum of the digits of that number. (Use the concept of self processing page.)
<html>
<body bgcolor = "navyblue">
<form action = "<?php echo $_SERVER['PHP_SELF'] ?>" method = "POST">
Enter the first number:
<input type = "text" name = "n1" id = "n1"> <BR>
<input type = "submit" value = "submit">
</form>
<?php
$num = $_POST['n1'];
$n1 = 0;
$n2 = 1;
echo "<BR> Fibonacci series are:<BR>";
echo "<BR> $n1";
echo "<BR> $n2";
for($i = 1; $i<=$num-2; $i++)
{
$n3 = $n1 + $n2;
echo "<BR> $n3";
$n1 = $n2;
$n2 = $n3;
}
$temp = $num;
$sum=0;
while($temp!=0)
{
$sum += $temp % 10;
$temp = $temp / 10;
}
echo "<BR>sum of digits of ".$num." is :".$sum;
?>
</body>
</html>
Fibonacci series are:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
sum of digits of 15 is :6
slip 30
Q. 1) Create a XML file which gives details of books available in “Bookstore” from following
categories.
1) Yoga
2) Story
3) Technical
and elements in each category are in the following format
Q12book.php
<?xml version="1.0" encoding="utf-8"?>
<Book_Detail>
<Technical>
<BOOK>
<Book_Title>TechBook </Book_Title>
<Book_Author> Sam </Book_Author>
<Book_Price> 1000 </Book_Price>
</BOOK>
</Technical>
<Cooking>
<BOOK>
<Book_Title>CookBook </Book_Title>
<Book_Author>Nil </Book_Author>
<Book_Price> 500 </Book_Price>
</BOOK>
</Cooking>
<Yoga>
<BOOK>
<Book_Title>YogaBook </Book_Title>
<Book_Author>Avi </Book_Author>
<Book_Price> 3000 </Book_Price>
</BOOK>
</Yoga>
</Book_Detail>
Q12book.php
<?php
$xml=simplexml_load_file("Q12book.xml") or die("cannnot load");
$xmlstring=$xml->asXML();
echo $xmlstring;
?>
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/css" href="university.css" ?>
<university>
<uni>
<name> sppu </name>
<city> pune </city>
<rank> 1 </rank>
</uni>
<uni>
<name> kolhapur </name>
<city> kl </city>
<rank> 2 </rank>
</uni>
<uni>
<name> nil </name>
<city> london </city>
<rank> 7 </rank>
</uni>
</university>
university.php
<?php
$doc = new DOMDocument();
$doc->load("university.xml");
$name = $doc->getElementsByTagName("name");
foreach($name as $v)
{
echo "<BR>$v->textContent";
}
?>
university.css
name
{
color:black;
font-family:copperplate G0thic Light;
font-size:16pt;
font:bold;
}
city,rank
{
color:yellow;
font-family: Arial;
font-size:12pt;
font:Bold;
}
customer.html
<html>
<body>
<form action="customer.php" method = "POST">
Enter the customer name:
<input type = "text" name = "name">
Enter the customer address:
<input type = "text" name = "add">
Enter the customer mobile no:
<input type = "text" name = "mno">
<input type = "submit" name = "submit">
</body>
</html>
customer.php
<?php
setCookie('s1',$_POST['name'],time()+3600);
setCookie('s2',$_POST['add'],time()+3600);
setCookie('s3',$_POST['mno'],time()+3600);
?>
<html>
<body>
<form action = "customer1.php" method ="POST">
Enter the product name:
<input type = "text" name = "pname">
Enter the product quantity:
<input type = "text" name = "pqnt">
Enter the product rate no:
<input type = "text" name = "prate">
<input type = "submit" name = "submit">
</body>
</html>
customer1.php
<?php
$name = $_COOKIE['s1'];
$add = $_COOKIE['s2'];
$mno = $_COOKIE['s3'];
$pname = $_POST['pname'];
$pqnt = $_POST['pqnt'];
$prate = $_POST['prate'];
$total = $pqnt * $prate;
echo "<table border=2>";
echo "<th colspan=3> Customer Information </th>";
echo "<tr>";
echo "<th> Name </th> <th> Address </th> <th> Mo.No </th> ";
echo "</tr>";
echo "<tr>";
echo "<td> $name </td> <td> $add </td> <td> $mno </td>";
echo "</tr>";
echo "</table>";
echo "<table border=2>";
echo "<th colspan=3> product Information </th>";
echo "<tr>";
echo "<th> Name </th> <th> Quantity </th> <th> Rate </th> ";
echo "</tr>";
echo "<tr>";
echo "<td> $pname </td> <td> $pqnt </td> <td> $prate </td>";
echo "</tr>";
echo "<tr> <td colspan = 3>Total: $total </td> </tr> ";
echo "</table>";
?>
| Customer Information | ||
|---|---|---|
| Name | Address | Mo.No |
| swapnil | london | 9356000093 |
| product Information | ||
|---|---|---|
| Name | Quantity | Rate |
| life | 2 | 100 |
| Total: 200 | ||
• Write a JavaScript to display
message ‘Exams are near, have you started preparing for?’ (use alert box ) and
Accept any two numbers from user and display addition of two number .(Use
Prompt and confirm box)
<html>
<head><title>Addition of two
numbers</title></head>
<body>
<form name="frm1">
<h1> Addition of two numbers </h1>
<input type="button" value="Display
Addition" onclick="check()">
</form>
<script type="text/javascript">
function check()
{
var a,b,c;
confirm("Exams are near, have you statred for
preparing?");
a=prompt("Enter first number");
b=prompt("Enter first number");
c=parseInt(a)+parseInt(b);
alert("Addition of two numbers is:-" +c);
}
</script>
</body>
</html>
• Write a Java Script Program to print Fibonacci numbers on
onclick event.
<html>
<head><title>Fibonacci
series</title></head>
<body>
<form name="frm1">
<h1> Fibonacci series </h1>
<input type="button" value="Display
Fibonacci series" onclick="check()">
</form>
<script type="text/javascript">
function check()
{
var a,b,c;
a=1; b=1;
document.write(a + "<br>" + b +
"<br>");
for(i=1;i<=10;i++)
{
c=a+b;
document.write(c + "<br>"); a=b;
b=c;
}
}
</script>
</body>
</html>
• Write a Javascript program to
accept name of student, change font color to red, font size to 18 if student
name is present otherwise on clicking on empty text box display image which
changes its size (Use onblur, onload, onmousehover, onmouseclick, onmouseup)
<html>
<head><title>Test
change program</title></head>
<body>
<form
name="frm1">
<h1> to Change text font color </h1>
Enter student
name:-
<input
type="text" id="demo" name="t1"
onblur="check()">
</form>
<script
type="text/javascript">
function check()
{
alert("hello");
var
a=frm1.t1.value;
if(a.length==0)
{
var x =
document.createElement("IMG");
x.setAttribute("src",
"C:\Users\Student\Pictures\nature1.jpg");
x.setAttribute("width",
"304");
x.setAttribute("height",
"228");
x.setAttribute("alt", "The
Pulpit Rock");
document.body.appendChild(x);
}
else
{
document.getElementById("demo").style.color ="blue";
document.getElementById("demo").style.fontSize
= "40";
}
}
</script>
</html>
• Write a Java Script Program to show Hello Good Morning
message onload event using alert box and display the Student registration from.
<html>
<head><title>Hello</title></head>
<body
onload="msg()">
<h1
align="center">Student Registration From </h1>
<form
name="f1" method="post">
Name:-
<input type="text"
name="t1"><br>
Adress:-
<textarea rows=3
cols=20></textarea><br>
Gender:-<br>
<input type="radio"
name="r1" value="male">Male <br>
<input type="radio"
name="r1" value="female">Female<br>
Mobile No.
<input type="number"
maxlength=10><br>
Subject:-<br>
<input type="checkbox"
name="c1">Biology<br>
<input type="checkbox"
name="c2">Physics<br>
<input type="checkbox"
name="c3">Chemistry<br>
<input type="checkbox"
name="c4">English<br>
<input type="checkbox"
name="c5">Mathematics<br>
<input
type="submit" value="submit">
<input
type="reset" value="Reset">
</form>
<script
type="text/javascript">
function msg()
{
alert("Hello
Good Morning");
}
</script>
</html>
• Write a Java Script Program to validate user name and
password on onSubmit event.
<html>
<head><title>javascript</title>
<script
type="text/javascript">
function
validate()
{
var user,pass,ans,ch;
ans="true";
user=f1.t1.value;
pass=f1.t2.value;
if(user.length<8||user.length>15||pass.length<6||pass.length>10)
{
alert("user
name having length 8 to 15 and password length is 6 to 10");
ans="false";
}
for(i=0;i<pass.length;i++)
{
ch=pass.charAt(i);
if(ch=="
"||ch=="("||ch==")"||ch=="{"||ch=="}"||ch=="?"||ch=="*"||ch=="."||ch==","
)
{
alert("space
and special symbols are not allowed in password");
ans="false";break;
}
}
for(i=0;i<user.length;i++)
{
ch=user.charAt(i);
if((ch<"a"
|| ch>"z")&&(ch<0 || ch>9))
{
alert("username
contains capital and lower alphabets");
ans="false";
break;
}
}
if(ans=="true")
alert("currect
user name and password");
else
alert("Wrong
user name and password, Re-enter ");
}
</script></head>
<body
bgcolor="yellow">
<h1
align="center">Validation of Password</h1>
<form
name="f1" method="post">
Enter your name:-
<input
type="text" name="t1"><br>
Enter password:-
<input
type="password"
name="t2"><br>
<center><input
type="button" value="validate" onMouseMove="validate()">
<input
type="reset" value="reset"></center>
</form></body></html>
<html>
<head><title>javascript</title>
<script type="text/javascript">
function validate()
{
var user,pass,ans;
ans="true";
user=f1.t1.value;
pass=f1.t2.value;
if(user.length<8||user.length>15||pass.length<6||pass.length>10)
{
alert("user name having length 8 to 15 and password length is 6 to 10");
ans="false";
}
if(ans=="true")
alert("currect user name and password");
else
alert("Wrong user name and password, Re-enter ");
}
</script></head>
<body bgcolor="yellow">
<h1 align="center">Validation of Password</h1>
<form name="f1" method="post">
Enter your name:-
<input type="text" name="t1"><br>
Enter password:-
<input type="password" name="t2"><br>
<center><input type="button" value="validate" onMouseMove="validate()">
<input type="reset" value="reset"></center>
</form></body></html>
d
d
Comment