You are on page 1of 14

Practical No.

7
Design a webpage to handle asynchronous requests using AJAX on
a. Mouseover
b. button click

a. Mouseover

<!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.
min.js"></script>
<script>
$(document).ready(function(){
$("p").mouseover(function(){
$("p").css("background-color", "yellow");
});
$("p").mouseout(function(){
$("p").css("background-color", "lightgray");
});
});
</script>
</head>
<body>

<p>Move the mouse pointer over this paragraph.</p>

</body>
</html>

b. Button click
<!DOCTYPE html>
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.
min.js"></script>
<script>
$(document).ready(function(){
$("p").click(function(){
alert("The paragraph was clicked.");
});
});
</script>
</head>
<body>

<p>Click on this paragraph.</p>

</body>
</html>
Practical No.8

Write PHP code for


a. Working with Databases (Storing Records / Reprieving Records and Display
them)
b. Storing and Retrieving Cookies
c. Storing and Retrieving Sessions

Solution:
b. Storing and Retrieving Cookies
<!DOCTYPE html>
<?php
setcookie("Auction_Item", "Luxury Car", time() + 2 * 24 * 60 * 60);
?>
<html>
<body>
<?php
if (isset($_COOKIE["Auction_Item"]))
{
echo "Auction Item is a " . $_COOKIE["Auction_Item"];
}
else
{
echo "No items for auction.";
}
?>
<p>
<strong>Note:</strong>
You might have to reload the page
to see the value of the cookie.
</p>
</body>
</html>
To Delete the cookie

<!DOCTYPE html>
<?php
setcookie("Auction_Item", "Luxury Car", time() + 2 * 24 * 60 * 60);
?>
<html>
<body>
<?php
setcookie("Auction_Item", "", time() - 60);
?>
<?php
echo "cookie is deleted"
?>
<p>
<strong>Note:</strong>
You might have to reload the page
to see the value of the cookie.
</p>

</body>
</html>
c. Storing and Retrieving Sessions
Starting Session
<?php

session_start();

?>

Storing Session Data


<?php

session_start();

$_SESSION["Rollnumber"] = "32";
$_SESSION["Name"] = "Dilip";

?>

Accessing session data


<?php

session_start();

echo 'The Name of the student is :' . $_SESSION["Name"] . '<br>';


echo 'The Roll number of the student is :' . $_SESSION["Rollnumber"] .
'<br>';

?>

Destroying Complete session


<?php

session_start();
session_destroy();

?>
Practical No.6
Create a XML file with Internal/External DTD and display using
a. CSS
b. XML
Solution:
book.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="Rules.css"?>
<books>
<heading>Welcome To GeeksforGeeks </heading>
<book>
<title>Title -: Web Programming</title>
<author>Author -: Chrisbates</author>
<publisher>Publisher -: Wiley</publisher>
<edition>Edition -: 3</edition>
<price> Price -: 300</price>
</book>
<book>
<title>Title -: Internet world-wide-web</title>
<author>Author -: Ditel</author>
<publisher>Publisher -: Pearson</publisher>
<edition>Edition -: 3</edition>
<price>Price -: 400</price>
</book>
<book>
<title>Title -: Computer Networks</title>
<author>Author -: Foruouzan</author>
<publisher>Publisher -: Mc Graw Hill</publisher>
<edition>Edition -: 5</edition>
<price>Price -: 700</price>
</book>
<book>
<title>Title -: DBMS Concepts</title>
<author>Author -: Navath</author>
<publisher>Publisher -: Oxford</publisher>
<edition>Edition -: 5</edition>
<price>Price -: 600</price>
</book>
<book>
<title>Title -: Linux Programming</title>
<author>Author -: Subhitab Das</author>
<publisher>Publisher -: Oxford</publisher>
<edition>Edition -: 8</edition>
<price>Price -: 300</price>
</book>
</books>

Rules.css
books {
color: white;
background-color : gray;
width: 100%;
}
heading {
color: green;
font-size : 40px;
background-color : powderblue;
}
heading, title, author, publisher, edition, price {
display : block;
}
title {
font-size : 25px;
font-weight : bold;
}
Practical No.5

Write JavaScript code for


a. Demonstrating different JavaScript Objects such as String, RegExp, Math,
Date
b. Demonstrating different JavaScript Objects such as Window, Navigator,
History, Location, Document,
c. Storing and Retrieving Cookies

a. Demonstrating different JavaScript Objects such as String, RegExp,


Math, Date

A1 Regular Expressions (RegExp)

<html>
<body>
<p>Regular Expression</p>
<button onclick="myfunction()">TRY IT</button>

<script>
function myfunction()
{
var str="All these are not possible using HTML";
var n=str.search(/possible/i);
document.write("<br>"+n+"<br>");
var res=str.replace(/possible/i,"POSSIBLE");
document.write("<br>"+res+"<br>");
var patt=/e/;
document.write("<br>"+patt.test(str)+"<br>");
}
</script>
</body>
</html>

A2 String Demonstration

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The length Property</h2>

<p>The length of the string is:</p>


<p id="demo"></p>

<script>
let text = "SYCS";
document.getElementById("demo").innerHTML = text.length;
</script>

</body>
</html>

A3 Math Demonstration

<html>
<body>
<p>Math Demonstration</p>
<script type="text/javascript">
document.write("PI= "+Math.PI+"<br>");
document.write("Random Number= "+Math.round(49.65)+"<br>");
document.write("Rounding= "+Math.round(6.43)+"<br>");
document.write("Power= "+Math.pow(10,3)+"<br>");
document.write("Square Root= "+Math.sqrt(64)+"<br>");
document.write("Absolute= "+Math.abs(-667.7)+"<br>");
document.write("Ceil= "+Math.ceil(6,4)+"<br>");
document.write("Floor= "+Math.floor(4,7)+"<br>");
document.write("Finding Max= "+Math.max(10,50,60,78,25)+"<br>");
document.write("Finding Min= "+Math.min(10,50,60,78,-25,-800)+"<br>");

</script>
</body>
</html>

A4 Date Demonstration

<html>
<body>
<p>Date Demonstration</p>
<script type="text/javascript">
document.write(Date());
var d= new Date;
document.write("<br>"+d+"<br>");

var d1=new Date("August30, 2004 17:11:00");


document.write("<br>"+d1+"<br>");

var d2=new Date("26061994");


document.write("<br>"+d2+"<br>");

var date=new Date();


document.write("Today's date: "+date.getDate()+"<br>");

var day=new Date();


document.write("Today's Day "+day.getDay()+"<br>");
</script>
</body>
</html>
b. Demonstrating different JavaScript Objects such as Window, Navigator,
History, Location, Document,

B1 WINDOW Object demonstration

<html>
<body>
<h1>Window object Demonstration</h2>
<script type="text/javascript">
function msg()
{
alert("Hello Alert Box");
}

function myFunction() {
confirm("Press a button!");
}
function promptfunction()
{
let person = prompt("Please enter your name", "Harry Potter");
if (person != null) {
document.write("Hello " + person + "! How are you today?");
}
}
</script>
<input type="button" value="click" onclick="msg()"/><br>
<input type="button" value="confirm" onclick="myFunction()"/><br>
<input type="button" value="prompt" onclick="promptfunction()"/><br>
</body>
</html>

B2 Navigator Object Demonstration

<html>
<body>
<h2>JavaScript Navigator Object</h2>
<script>
document.writeln("<br/>navigator.appCodeName: "+navigator.appCodeName);
document.writeln("<br/>navigator.appName: "+navigator.appName);
document.writeln("<br/>navigator.appVersion: "+navigator.appVersion);
document.writeln("<br/>navigator.cookieEnabled: "+navigator.cookieEnabled);
document.writeln("<br/>navigator.language: "+navigator.language);
document.writeln("<br/>navigator.userAgent: "+navigator.userAgent);
document.writeln("<br/>navigator.platform: "+navigator.platform);
document.writeln("<br/>navigator.onLine: "+navigator.onLine);

</script>
</body>
</html>

B3 History Object Demonstration

<html>
<head>
<script>
function goback()
{
window.history.back()
}
</script>
</head>
<body>
<input type="button" value="goback" onclick="goback()">
</body>
</html>

B4 Location Object Demonstration

<!DOCTYPE html>
<html>
<body>
<h3> JavaScript function </h3>
<h4> The javascript window.location.href object </h4>
<button onclick = "getLocation()">
Get Href URL
</button>
<script>
function getLocation() {
// Get the current location
var location_var = window.location.href;
alert(location_var);
}
</script>
</body>
</html>
c. Storing and Retrieving Cookies

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="button" value="setCookie" onclick="setCookie()">
<input type="button" value="getCookie" onclick="getCookie()">
<script>
function setCookie()
{
document.cookie="username=Duke Martin";
}
function getCookie()
{
if(document.cookie.length!=0)
{
alert(document.cookie);
}
else
{
alert("Cookie not available");
}
}
</script>

</body>
</html>

You might also like