Web Technologies Lab Manual
Web Technologies Lab Manual
Program:
<html>
<head>
</head>
<body>
<script>
function insert(num){
document.form.textView.value=document.form.textView.value+num;
function equal(){
if(exp){
document.form.textView.value=eval(document.form.textView.value);
function c(){
document.form.textView.value=" ";
</script>
<center>
<form name="form">
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 >
if(isNaN(str))
str = str.toUpperCase();
if(chr == 'A' || chr == 'E' || chr == 'I' || chr == 'O' || chr == 'U')break;
if( i<str.length )
else
else
var num,rev=0,remainder;
num = parseInt(str);
while(num!=0) {
remainder = num%10;
num = parseInt(num/10);
</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.
Program:<?php
$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 )
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.
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)
</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 "<br/>";
echo "<br/>";
echo "<br/>";
if($n===$p){
$result=array();
$result[$i][$j] = 0;
}}
echo "<br/>";
} } ?>
OUTPUT :
123
456
789
789
456
123
the transpose of the first matrix:
147
258
369
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)
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;
}
</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);
}
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 = [];
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: