0% found this document useful (0 votes)
14 views30 pages

Web Technologies Lab Manual

Lab manual

Uploaded by

22781a1210svcet
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)
14 views30 pages

Web Technologies Lab Manual

Lab manual

Uploaded by

22781a1210svcet
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
You are on page 1/ 30

WEB TECHNOLOGIES LAB

1.Write a JavaScript to design a simple calculator to perform the following operations:


sum, product, difference and quotient.
Aim: To design a simple calculator to perform the following operations: sum, product, difference and
quotient.

Program:

<html>

<head>

</head>

<body>

<script>

function insert(num){

document.form.textView.value=document.form.textView.value+num;

function equal(){

var exp = document.form.textView.value;

if(exp){

document.form.textView.value=eval(document.form.textView.value);

function c(){

document.form.textView.value=" ";

</script>

<center>

<form name="form">

<input type="text" name="textView"/><br>

<input type="button" value="1" onclick="insert(1)"/>

<input type="button" value="2" onclick="insert(2)"/>


<input type="button" value="3" onclick="insert(3)"/>
<input type="button" value="+" onclick="insert('+')"/>
<br><br>
<input type="button" value="4" onclick="insert(4)"/>
<input type="button" value="5" onclick="insert(5)"/>
<input type="button" value="6" onclick="insert(6)"/>
<input type="button" value="-" onclick="insert('-')"/>
<br><br>
<input type="button" value="6" onclick="insert(6)"/>
<input type="button" value="7" onclick="insert(7)"/>
<input type="button" value="8" onclick="insert(8)"/>
<input type="button" value="*" onclick="insert('*')"/>
<br><br>
<input type="button" value="0" onclick="insert(0)"/>
<input type="button" value="/" onclick="insert('/')"/>
<input type="button" value="=" onclick="equal()"/>
<input type="button" value="C" onclick="c()"/>
<br>
</form>
</center>
</body>
</html>
Output:

2.Write a JavaScript that calculates the squares and cubes of the numbers from 0 to 10 and outputs
HTML text that displays the resulting values in an HTML table format
Aim: To calculates the squares and cubes of the numbers from 0 to 10 and outputs by using HTML
text that displays the resulting values in an HTML table format.

Program:

<html>

<head>

</head>

<body>

<center>

<table border="1">

<tr><th>number</th><th>square</th><th>cube</th></tr>

<script>

for(var i=0;i<=10;i++)

document.write("

<tr><td>"+i+"</td><td>"+i*i+"</td><td>"+i*i*i+"</td></tr>

"); }

</script>

</table>

</center>

</body>

</html>

Output:
3.Write a JavaScript code that displays text TEXT-GROWING with increasing font size in the interval
of 100ms in RED COLOR, when the font size reaches 50pt it displays TEXTSHRINKING in BLUE color.
Then the font size decreases to 5pt.

Aim: To write a JavaScript code that displays text TEXT-GROWING with increasing font size in the
interval of 100ms in RED COLOR, when the font size reaches 50pt it displays TEXTSHRINKING in BLUE
color. Then the font size decreases to 5pt.

Program:

<html>

<head>

</head>

<body>

<center>

<p id="demo"/>

</center>

<script>

var var1=setInterval(inTimer,1000);

var size=5;

var ids=document.getElementById("demo");

function inTimer(){

size+=5;

ids.innerHTML="TEXT GROWING";

ids.setAttribute("style","font-size:"+size+"px; color:red");

if(size>=50)

clearInterval(var1);

var var2=setInterval(deTimer,1000);

}
function deTimer(){

size-=5;

ids.innerHTML="TEXT SHRINKING";

ids.setAttribute("style","font-size:"+size+"px; color:blue");

if(size<=5)

clearInterval(var1);

}}

</script>

</body>

</html>

Output:
4. Develop and demonstrate a HTML5 file that includes JavaScript script that uses functions for the
following problems:

1. Parameter: A string
2. Output: The position in the string of the left-most vowel
3. Parameter: A number
4. Output: The number with its digits in the reverse order

Aim: . To develop and demonstrate a HTML5 file that includes JavaScript script that uses functions.

Program:

<html>

<body>

<script >

var str = prompt("Enter the Input","");

if(isNaN(str))

str = str.toUpperCase();

for(var i = 0; i<str.length; i++) {

var chr = str.charAt(i);

if(chr == 'A' || chr == 'E' || chr == 'I' || chr == 'O' || chr == 'U')break;

if( i<str.length )

alert("The position of the left most vowel is "+(i+1));

else

alert("No vowel found in the entered string");

else

var num,rev=0,remainder;
num = parseInt(str);

while(num!=0) {

remainder = num%10;

num = parseInt(num/10);

rev = rev * 10 + remainder;

alert("Reverse of "+str+" is "+rev);

</script>

</body>

</html>

Output:
5.Design an XML document to store information about a student in SVCET College. The information
must include USN, Name, and Name of the College, Programme, Year of Joining, and email id. Make
up sample data for 3 students. Create a CSS style sheet and use it to display the document

Aim: To design an XML document to store information about a student in SVCET College.

Program:

<?xml-stylesheet
href="style5.css"?>
<html>
<head>
<h1>Student Description</h1>
</head>
<students>
<student>
<usn>USN: 4MT15CS010</usn>
<name>Name: AnanthaPadmanabha</name>
<college>College: Sri Venkateswara College of
engineeringandtechnology </college>
<branch>Branch: Computer Science Engineering</branch>
<yoj>Year: 2015</yoj>
<email>E-mail: [email protected]</email>
</student>
<student>
<usn>USN: 4MT15CS011</usn>
<name>Name: Anil Kumar K</name>
<college>College: Sri Venkateswara College of
engineeringandtechnology </college>
<branch>Branch: Computer Science Engineering</branch>
<yoj>Year: 2015</yoj>
<email>E-mail: [email protected]</email>
</student>
<student>
<usn>USN: 4MT15CS012</usn>
<name>Name: Ankitha Shetty</name>
<college>College: Sri Venkateswara College of
engineeringandtechnology</college>
<branch>Branch: Computer Science Engineering</branch>
<yoj>Year: 2015</yoj>
<email>E-mail: [email protected]</email>
</student>
</students>
</html>
Style5.css

{
font-size: 28px;
background-color: black;
color: white;
display: block;
}
Student
{
margin-top: 10px;
}
Usn
{
color: rgb(200,200,0);
margin-left: 10px;
font-size: 24px;
}
Name
{
color: green;
margin-left: 20px;
font-size: 24px;
}
Yoj
{
color: orange;
margin-left: 20px;
font-size: 24px;
}
College
{
color: blue;
margin-left: 20px;
font-size: 20px;
}
Branch
{
color: red;
margin-left: 20px;
font-size: 20px;
}
Email
{
color: violet;
margin-left: 20px;
font-size: 20px;
}

Output:
6.Write a PHP program to keep track of the number of visitors visiting the web page and to display
this count of visitors, with proper headings.

Basic steps required

1.Create a file with .php extension in wamp(inside www directory ) &xamp(inside


htdocs directory)
2Run the file in PHP environment like localhost
Aim: To write a PHP program to keep track of the number of visitors visiting the web page and to
display this count of visitors.

Program:<?php

echo"No of Visitor is:";

$handler=fopen("file.txt","r");

$hit=(int)fread($handler,20);

fclose($handler);

$hit++;

$handler=fopen("file.txt","w");

fwrite($handler,$hit);

fclose($handler);

echo $hit;

?>
STEPS:( click on image to zoom )

Output: :( click on image to zoom )


7. Write a PHP program to display a digital clock which displays the current time of the server.

Aim: To Implement a PHP program to display a digital clock which displays the current time of the
server.

Program:

<head>
<meta http-equiv="refresh" content="1"/>
<st
yle
>
p{
color:ye
llow;
font-
size:90
px;
position:abs
olute; top:
40%;
left: 50%;
transform: translate(-50%, -50%);
}
body {
background-color:maroon;
}
</style>
<p> <?php echo date(" h: i : s A");?> </p>
</head>
STEPS

OUTPUT
8. Write the PHP programs to do the following:
1. Implement simple calculator operations.
2. Find the transpose of a matrix.
3. Multiplication of two matrices.
4. Addition of two matrices.

Aim : To Implement simple calculator operations.

prog8a.php

<html>
<head>
<style>
table, td,
th {
border: 1px solid black;
width: 35%;
text-align: center;
background-color:
lightgray;
}
table { margin: auto; }
input,p { text-
align:right; }
</style>
</head>

<body>
<form method="post" action="prog8a.php">
<table>
<caption><h2> SIMPLE CALCULATOR </h2></caption>
<tr>
<td>First Number:</td><td><input type="text" name="num1" /></td>
<td rowspan="2"><button type="submit" name="submit"
value="calculate">Calculate</td></tr>
<tr>
<td>Second Number:</td><td><input type="text" name="num2"/></td>
</tr>
</form>

<?php
if(isset($_POST['submit'])) // it checks if the input submit is filled
{
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
if(is_numeric($num1) and
is_numeric($num2) )
{
echo "<tr><td> Addition
:</td><td><p>".($num1+$num2)."</p></td>"; echo "<tr><td>
Subtraction :</td><td><p> ".($num1-$num2)."</p></td>";
echo "<tr><td> Multiplication
:</td><td><p>".($num1*$num2)."</p></td>"; echo
"<tr><td>Division :</td><td><p> ".($num1/$num2)."</p></td>";
echo "</table>";
}
else
{
echo"<script> alert(' ENTER VALID NUMBER');</script>";
}
}
?>
</body>
</html>

STEPS
OUTPUT:
8b.SOLUTION 1
prog8b.php

<!DOCTYPE html>
<html>
<body>
<?php
function pr($a){
foreach ($a as $b) {
foreach ($b as $c) {
echo $c ." ";
}echo "<br>";
}echo "<br>";
}

$a = [[1,2,3],[4,5,6],[7,8,9]];
$b = [[7,8,9],[4,5,6],[1,2,3]];
echo "<b>First Matrix : </b><br>" ; pr($a);
echo "<b>Second Matrix : </b><br>"; pr($b);
for ($i=0; $i < 3; $i++)
for ($j=0; $j < 3; $j++)
$c[$i][$j] = $a[$j][$i];
echo "<b>Transpose Of First Matrix : </b><br>"; pr($c)

for ($i=0; $i < 3; $i++) for


($j=0; $j < 3; $j++)
$c[$i][$j] = $a[$i][$j] + $b[$i][$j];
echo "<b>Addition Of Two Matrix : </b><br>"; pr($c);
for ($i=0; $i < 3; $i++)
for ($j=0; $j < 3; $j++){
$c[$i][$j] = 0;
for ($k=0; $k < 3; $k++)
$c[$i][$j] += $a[$i][$k] * $b[$k][$j];
} echo "<b>Multiplication Of Two Matrix : </b><br>"; pr($c); ?>

</body>

</html>
STEPS

OUTPUT
prog8b.php
<?php

$a = array(array(1,2,3),array(4,5,6),array(7,8,9));

$b = array(array(7,8,9),array(4,5,6),array(1,2,3));

$m=count($a);

$n=count($a[2]);

$p=count($b);

$q=count($b[2]);

echo "the first matrix :"."<br/>";

for ($row = 0; $row < $m; $row++) {

for ($col = 0; $col < $n; $col++)

echo " ".$a[$row][$col];

echo "<br/>";

echo "the second matrix :"."<br/>";

for ($row = 0; $row < $p; $row++) {

for ($col = 0; $col < $q; $col++)

echo " ".$b[$row][$col];

echo "<br/>";

echo "the transpose for the first matrix

is:"."<br/>"; for ($row = 0; $row < $m; $row++) {

for ($col = 0; $col < $n; $col++)

echo " ".$a[$col][$row];

echo "<br/>";

if(($m===$p) and ($n===$q)) {

echo "the addition of matrices is:"."<br/>";


for ($row = 0; $row < 3; $row++) {

for ($col = 0; $col < 3; $col++)

echo " ".$a[$row][$col]+$b[$row][$col]."

"; echo "<br/>";

if($n===$p){

echo " The multiplication of matrices: <br/>";

$result=array();

for ($i=0; $i < $m; $i++) {

for($j=0; $j < $q; $j++){

$result[$i][$j] = 0;

for($k=0; $k < $n; $k++)

$result[$i][$j] += $a[$i][$k] * $b[$k][$j];

}}

for ($row = 0; $row < $m; $row++) {

for ($col = 0; $col < $q; $col++)

echo " ".$result[$row][$col];

echo "<br/>";

} } ?>
OUTPUT :

the first matrix:

123

456

789

the second matrix:

789

456

123
the transpose of the first matrix:
147
258
369

the addition of matrices is:


8 10 12
8 10 12
8 10 12

the multiplication of matrices:


18 24 30
54 69 84
90 114 138
09. WRITE A PHP PROGRAM NAMED STATES.PY THAT DECLARES A
VARIABLE STATES WITH VALUE "MISSISSIPPI ALABAMA TEXAS
MASSACHUSETTS KANSAS". WRITE A PHP PROGRAM THAT DOES THE
FOLLOWING:

A. SEARCH FOR A WORD IN VARIABLE STATES THAT ENDS IN XAS. STORE THIS WORD IN
ELEMENT 0 OF A LIST NAMED STATESLIST.

B. SEARCH FOR A WORD IN STATES THAT BEGINS WITH K AND ENDS IN S. PERFORM A
CASEINSENSITIVE COMPARISON. [NOTE: PASSING RE.IAS A SECOND PARAMETER TO
METHOD COMPILE PERFORMS A CASE- INSENSITIVE COMPARISON.] STORE THIS WORD
IN ELEMENT1 OF STATESLIST.

C. SEARCH FOR A WORD IN STATES THAT BEGINS WITH M AND ENDS IN S. STORE THIS
WORD IN ELEMENT 2 OF THE LIST.

D. SEARCH FOR A WORD IN STATES THAT ENDS IN A. STORE THIS WORD IN ELEMENT 3 OF
THE LIST.

SOLUTION 1

1. If xampp is in the system, save the program in C:\xampp\htdocs (start apache in xampp control panel)

2. If no xampp in the system, save the program in C:\Program Files\Apache


Group\Apache2\htdocs & Open Google Chrome & type http://localhost/prog9.php

prog9.php

<html>
<body>
<?php
$states = "Mississippi Alabama Texas Massachusetts Kansas";
$b = explode(' ',$states);
echo "<br>ORIGINAL ARRAY :<br>";
foreach ( $b as $i => $value )
echo "states[$i] = $value<br>";
foreach ($b as $c)
{

$n = strlen($c);
if($c[$n-1]=='s' && $c[$n-2]=='a' && $c[$n-3]=='x') $d[0] = $c;
if($c[0]=='K' && $c[$n-1]=='s') $d[1] = $c;
if($c[0]=='M' && $c[$n-1]=='s') $d[2] = $c;
if($c[$n-1]=='a') $d[3] = $c;
}

echo "<br>RESULTANT ARRAY :<br>";


for ($i=0; $i < count($d); $i++)
echo "statesList[$i] = $d[$i]<br>";
?>

</body>
</html>

STEPS

OUTPUT
SOLUTION 2

prog9.php
<?php
$states = "Mississippi Alabama Texas
Massachusetts Kansas"; $statesArray = [];
$states1 = explode(' ',$states);
echo "Original Array :<br>";
foreach ( $states1 as $i => $value )
print("STATES[$i]=$value<br>");
foreach($states1 as $state) {
if(preg_match( '/xas$/', ($state)))
$statesArray[0] = ($state);
}

foreach($states1 as $state) {

if(preg_match('/^k.*s$/i', ($state)))
$statesArray[1] = ($state);
}

foreach($states1 as $state) {
if(preg_match('/^M.*s$/', ($state)))
$statesArray[2] = ($state);
}

foreach($states1 as $state){
if(preg_match('/a$/', ($state)))
$statesArray[3] = ($state);
}

echo "<br><br>Resultant Array :<br>";


foreach ( $statesArray as $array => $value )
print("STATES[$array]=$value<br>");
?>
OUTPUT

STEPS TO EXECUTE PHP PROGRAM


1. Copy the php code given below
2. Save it with .php file name extension
3. Place the file in the htdocs of XAAMP
4. Start the XAAMP control panel
5. Start Apache server
6. Click on admin in XAMPP Control pale
7. Replace the url dashboard name with your php file name
8. Execution completed
9.

Solution
prog9.php
<html>
<body>
<?php
$states = "Mississippi Alabama Texas Massachusetts Kansas";
$b = explode(' ',$states);
echo "<br>ORIGINAL ARRAY :<br>";
foreach ( $b as $i =>
$value ) echo "states[$i] =
$value<br>"; foreach ($b
as $c)

{
$n = strlen($c);
if($c[$n-1]=='s' && $c[$n-2]=='a' && $c[$n-3]=='x') $d[0] = $c;
if($c[0]=='K' && $c[$n-1]=='s') $d[1] = $c;
if($c[0]=='M' && $c[$n-1]=='s') $d[2] = $c;
if($c[$n-1]=='a') $d[3] = $c;
}
echo "<br>RESULTANT ARRAY :<br>";
for ($i=0; $i < count($d);
$i++) echo "statesList[$i]
= $d[$i]<br>";

?>

WEB</body>
TECHNOLOGY – Output
</html>
10. Write a PHP program to sort the student records which are stored in
the database using selection sort.

<!DOCTYPE
html>
<html>
<head>

</head>
<body>
<?php
$domain = "localhost";
$username = "root";
$password = "";
$dbname = "weblab";
$a = [];

$conn = mysqli_connect($domain, $username, $password, $dbname);

if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);
$sql = "SELECT * FROM student";

$result = $conn->query($sql);
echo "<br>";
echo "<h2>BEFORE SORTING</h2>";
echo "<table border='2'>";
echo "<tr>";
echo "<th>USN</th><th>Name</th><th>Address</th></tr>";
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["usn"] . "</td>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["address"] . "</td></tr>";
array_push($a, $row["usn"]);
}
} else
echo "Table is Empty";
echo "</table>";

$n = count($a);
for ($i = 0; $i < ($n - 1); $i++) {

$pos = $i;
for ($j = $i + 1; $j < $n; $j++) {
if ($a[$pos] > $a[$j])
$pos = $j;
}
if ($pos != $i) {
$temp = $a[$i];
$a[$i] = $a[$pos];
$a[$pos] = $temp;
} }

$c = [];
$d = [];
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
if ($row["usn"] == $a[$i]) {
$c[$i] = $row["name"];
$d[$i] = $row["address"];
}}}}
echo "<br>";
echo "<h2>AFTER SORTING</h2>";
echo "<table border='2'>";
echo "<tr>";
echo
"<th>USN</th><th>NAME</th><th>Address</th></tr>"
;
for ($i = 0; $i < $n; $i++) {
echo "<tr>";
echo "<td>" . $a[$i] . "</td>";
echo "<td>" . $c[$i] . "</td>";
echo "<td>" . $d[$i] . "</td></tr>";
}
echo "</table>";
$conn->close();
?>
</body>
OUTPUT:

You might also like