CSS (22519) Manual
CSS (22519) Manual
CSS (22519) Manual
(Code : 1547) has completed the term work satisfactorily in course Client Side
Seal of Institution
Practical No 1: Write simple JavaScript with HTML for arithmetic
expression evaluation and message printing.
Output :
❖ Develop a JavaScript program to perform following arithmetic
operations: addition, subtraction, multiplication and division.
<html>
<head>
<title>Arithmetic Operations</title>
</head>
<body>
<script type=”text/javascript”>
Var a = 12;
Var b = 34;
Var result;
Document.write(“Value of a = “ + a + “ and b = “+ b);
Result = a + b;
Document.write(“<br>Addition of a & b = “ + result );
Result = a – b;
Document.write(“<br>Subtraction of a & b = “ + result );
Result = a * b;
Document.write(“<br>Multiplication of a & b = “ + result );
Result = a / b;
Document.write(“<br>Division of a & b = “ + result );
</script>
</body>
</html>
Output :
Practical No. 2:-Develop JavaScript to use decision making and
looping statements
var a = 1;
</script>
</body>
</html>
Output :
Output :
Practical No-3.Develop JavaScript to implements Array
functionalities
Array.prototype.displayItems=function(){
for (i=0;i<this.length;i++){
document.write(this[i] + "<br />");
}
}
document.write("Programming lanugages array<br />");
languages.displayItems();
languages.displayItems();
languages.displayItems();
document.write("<br />The languages array after REMOVING the LAST item<br />");
languages.pop();
languages.displayItems();
languages.push("JavaScript");
languages.displayItems();
languages.shift();
languages.displayItems();
</script>
</head>
<body>
</body>
</html>
Output :
❖ Develop a JavaScript program to display the sum and product of array
elements.
<html>
<head>
<title>Display sum and product of array elements</title>
</head>
<body>
<script type=”text/javascript">
sum += arr[i];
product *= arr[i];
}
</script>
</body>
</html>
Output :
Practical No-4 : Develop javascript to implement functions
Output :
Practical No-5 : Develop javascript to implement Strings.
function toUpper() {
var text = document.getElementById('panel').innerHTML
document.getElementById('panel').innerHTML = text.toUpperCase()
}
function toLower() {
var text = document.getElementById('panel').innerHTML
document.getElementById('panel').innerHTML = text.toLowerCase()
}
</script>
</head>
<body>
</body>
</html>
Output :
function countVowels(s)
{
var i=0, count=0
var ch
for(var i=0; i<s.length; i++)
{
ch = s.charAt(i)
if(ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' ||
ch == 'u' || ch == 'U')
{
count++
}
}
return count
}
</script>
</body>
</html>
Output :
Practical No-6 : Create web page using Form Elements
Output :
Practical No-7 : Create web page to implement Form Events. Part I
<html>
<body>
<button id=”btn”>Click here</button>
<p id=”para" onmouseover="mouseOver()" onmouseout="mouseOut()">Hover over
this Text !</p>
<b id="output"></b>
<script>
var x = document.getElementById("btn");
x.addEventListener("click", btnClick);
function mouseOver() {
document.getElementById("output").innerHTML += "MouseOver Event" +
"<br>";
}
function mouseOut() {
document.getElementById("output").innerHTML += "MouseOut Event" + "<br>";
}
function btnClick() {
document.getElementById("output").innerHTML += "Click Event" + "<br>";
}
</script>
</body>
</html>
Output :
❖ Write HTML Script that displays three radio buttons red, green, blue.
Write proper JavaScript such that when the user clicks on radio button
the background color of webpage will get change accordingly.
<html>
<head>
<script>
function changeColor(color)
{
var panel = document.getElementById('panel')
document.body.style.backgroundColor = color
panel.innerHTML = "Background color is set to: " + color.toUpperCase()
}
</script>
</head>
<body onload="changeColor('red')">
<p>Select option to change background color of page</p>
<form name="myform">
<input type="radio" name="color" value="red" onchange="changeColor(this.value)"
checked="false">RED<br />
<input type="radio" name="color" value="green"
onchange="changeColor(this.value)">GREEN<br />
<input type="radio" name="color" value="blue"
onchange="changeColor(this.value)">BLUE<br />
</form>
<p id="panel"></p>
</body>
</html>
Output :
Practical No-8 : Create web page to implement Form Events. Part II
Load Events:-
1. onload event
<!DOCTYPE html>
<html>
<body onload="checkCookies()">
<p id="demo"></p>
<script>
function checkCookies() {
var text = "";
if (navigator.cookieEnabled == true) {
text = "Cookies are enabled.";
} else {
text = "Cookies are not enabled.";
}
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
</html>
Output :
Cookies are enabled.
2. Onunload event
<!DOCTYPE html>
<html>
<body onunload="myFunction()">
<script>
function myFunction() {
alert("Thank you for visiting W3Schools!");
}
</script>
</body>
</html>
Output :
Welcome to my Home Page
Note: Due to different browser settings, this event may not always work as expected.
Key Events
1. onkeypress event
<!DOCTYPE html>
<html>
<body>
<p>A function is triggered when the user is pressing a key in the input field.</p>
<script>
function myFunction() {
alert("You pressed a key inside the input field");
}
</script>
</body>
</html>
Output :
2. onkeyup event
<!DOCTYPE html>
<html>
<body>
<p>A function is triggered when the user releases a key in the input field. The function
transforms the character to upper case.</p>
Enter your name: <input type="text" id="fname" onkeyup="myFunction()">
<script>
function myFunction() {
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
</script>
</body>
</html>
Output :
A function is triggered when the user releases a key in the input field. The function
transforms the character to upper case.
<!DOCTYPE html>
<html>
<body>
<p>A function is triggered when the user is pressing a key in the input field.</p>
<script>
function myFunction() {
alert("You pressed a key inside the input field");
}
</script>
</body>
</html>
Output :
Other Events
1. onchange event
<html>
<head>
<script>
functionmyFunction() {
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
</script>
</head>
<body>
Enter your name: <input type="text" id="fname" onchange="myFunction()">
</body>
</html>
2. onselect event
<html>
<head>
<script>
functionmyFunction()
{
document.write("selected some text");
}
</script>
</head>
<body>
Some text: <input type="text" value="Hello world!" onselect="myFunction()">
</body>
</html>
3. onfocus event
<html>
<head>
<script>
functionmyFunction(x)
{
x.style.background = "yellow";
}
</script>
</head>
<body>
Enter your name: <input type="text" onfocus="myFunction(this)">
</body>
</html>
4. onblur event
<html>
<head>
<script>
functionmyFunction()
{
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
</script>
</head>
<body>
Enter your name: <input type=”text” id=”fname” onblur=”myFunction()”>
</body>
</html>
5. onreset event
<html>
<head>
<script>
function message() {
alert("This alert box was triggered by the onreset event handler");
}
</script>
</head>
<body>
<form onreset="message()">
Enter your name: <input type="text" size="20">
<input type="reset">
</form>
</body>
</html>
6. onsubmit event
<html>
<head>
<script>
functionconfirmInput()
{
fname = document.forms[0].fname.value;
alert("Hello " + fname + "! You will now be redirected to My Page");
}
</script>
</head>
<body>
<form onsubmit="confirmInput()" action="https://google.com/">
Enter your name: <input id="fname" type="text" size="20">
<input type="submit">
</form>
</body>
</html>
Practical No:-9 : Develop a webpage using intrinsic java functions
<html>
<head>
<title>Insert a string within a specific position in another string</title>
</head>
<body>
<script>
function insert(main_string, ins_string, pos) {
if(typeof(pos) == "undefined") {
pos = 0;
}
if(typeof(ins_string) == "undefined") {
ins_string = '';
}
return main_string.slice(0, pos) + ins_string +
main_string.slice(pos);
}
var main_string = "Welcome to JavaScript";
var ins_string = " the world of ";
var pos = 10;
var final_string = insert(main_string, ins_string, pos);
document.write("Main String: <b>" + main_string + "</b><br/>");
document.write("String to insert: <b>" + ins_string + "</b><br/>");
document.write("Position of string: <b>" + pos + "</b><br/>");
document.write("Final string: <b>" + final_string + "</b>");
</script>
</body>
</html>
Output :
Practical No:-10 : Develop a webpage for creating session and
persistent cookies. Observe the effects with browser cookies settings.
❖ Storing Cookies
<html>
<head>
<script type = "text/javascript">
functionWriteCookie() {
if(document.myform.customer.value == "" )
{
alert("Enter some value!");
return;
}
cookievalue = escape(document.myform.customer.value) + ";";
document.cookie = "name=" + cookievalue;
document.write ("Setting Cookies : " + "name=" + cookievalue );
}
</script>
</head>
<body>
<form name = "myform" >
Enter name: <input type = "text" name = "customer"/>
<input type = "button" value = "Set Cookie" onclick = "WriteCookie();"/>
</form>
</body>
</html>
Output :
Enter Name :
Set Cookie
Output :
Click the following button and see the result:
Get Cookie
Output :
Enter name :
Set Cookie
Output :
Enter name :
Set Cookie
Practical No.11 : Develop a webpage for placing the window on the
screen and Working with child window.
Program Code :
<html>
<body>
<p>Click the button to open a new window and close the window after three seconds (3000
milliseconds)</p>
<button onclick="openWin()">Open "myWindow"</button>
<script>
function openWin() {
var myWindow = window.open("", "myWindow", "width=200, height=100");
myWindow.document.write("<p>This is 'myWindow'</p>");
setTimeout(function(){ myWindow.close() }, 3000);
}
</script>
</body>
</html>
Output :
Click the button to open a new window and close the window after three
seconds (3000 milliseconds)
Program code :
<!DOCTYPE html>
<html>
<head>
<title>creating mailing system</title>
<style>
legend {
display: block;
padding-left: 2px;
padding-right: 2px;
border: none;
}
</style>
<script type="text/javascript">
function validate() {
var user = document.getElementById("e").value;
var user2 = document.getElementById("e");
var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (re.test(user)) {
alert("done");
return true;
}
else {
user2.style.border = "red solid 3px";
return false;
}
}
</script>
</head>
<body bgcolor="cyan">
<center>
<h1>Email Registration</h1>
<form>
<fieldset style="width:300px">
<legend>Registation Form</legend>
<table>
<tr>
<input type="text"
placeholder="firstname"
maxlength="10">
</tr>
<br><br>
<tr>
<input type="text"
placeholder="lastname"
maxlength="10">
</tr>
<br><br>
<tr>
<input type="email"
placeholder="[email protected]" id="e">
</tr>
<br><br>
<tr>
<input type="password" placeholder="password">
</tr>
<br><br>
<tr>
<input type="password" placeholder="confirm">
</tr>
<br><br>
<tr>
<input type="text" placeholder="contact">
</tr>
<br><br>
<tr>
<label>Gender:</label>
<select id="gender">
<option value="male">male</option>
<option value="female">female</option>
<option value="others">others</option>
</select>
</tr>
<br><br>
<tr><input type="submit"
onclick="validate()" value="create">
</tr>
</table>
</fieldset>
</form>
</center>
</body>
</html>
Output:
Practical.No.13 : Create web page with Rollovers effect.
Program code :
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<script language=”Javascript”>
MyBooks=new Array(‘vb2010book.jpg’,’vb2008book.jpg’,’vb6book.jpg’)
book=0
function ShowCover(book){document.DisplayBook.src=MyBooks[book]
}</script></head>
<body>
<body>
<table border=0>
<tr>
</td>
</tr>
</table>
</body>
</html>
Output :
View Example 30.4 in action.
Practical.No.14 : Develop a webpage for implementing Menus
Program Code :
<html>
<head>
<script language="javascript" type="text/javascript">
function dynamicdropdown(listindex)
{
switch (listindex)
{
case "manual" :
document.getElementById("status").options[0]=new Option("Select status","");
document.getElementById("status").options[1]=new Option("OPEN","open");
document.getElementById("status").options[2]=new Option("DELIVERED","delivered");
break;
case "online" :
document.getElementById("status").options[0]=new Option("Select status","");
document.getElementById("status").options[1]=new Option("OPEN","open");
document.getElementById("status").options[2]=new Option("DELIVERED","delivered");
document.getElementById("status").options[3]=new Option("SHIPPED","shipped");
break;
}
return true;
}
</script>
</head>
<title>Dynamic Drop Down List</title>
<body>
<div class="category_div" id="category_div">Source:
<select id="source" name="source" onchange="javascript:
dynamicdropdown(this.options[this.selectedIndex].value);">
<option value="">Select source</option>
<option value="manual">MANUAL</option>
<option value="online">ONLINE</option>
</select>
</div>
<div class="sub_category_div" id="sub_category_div">Status:
<script type="text/javascript" language="JavaScript">
document.write('<select name="status" id="status"><option value="">Select
status</option></select>')
</script>
</div>
</body>
</html>
Output :
Select source ^
Source :
OPEN ^
Status :
Practical.No.15 : Develop a webpage for implementing Status bars
and web page protection.
Output :
Watch the text scroll at the bottom of this window!
<html>
<head>
<script language="JavaScript">
function function2() {
alert("This image is copyrighted")
}
</script>
</head>
<body oncontextmenu="function2()">
<p>Right click in the image.</p>
<img oncontextmenu="function2()"
src="http://www.java2s.com/style/logo.png"
alt="www.java2s.com"
width="99"
height="76">
</body>
</html>
Output :
Practical No: 16 : Develop a web page for implementing slideshow,
banner.
Output :
View banner.htm to see the above JavaScript in action
❖ Creating Rotating Banner Ads with URL Links
<html>
<head>
<script language="Javascript">MyBanners=new
Array('banner1.jpg','banner2.jpg','banner3.jpg','banner4.jpg')
MyBannerLinks=new
Array('http://www.vbtutor.net/','http://www.excelvbatutor.com/','http://onlinebizguide4yo
u.com/','http://javascript-tutor.net/')
banner=0
function ShowLinks(){
document.location.href="http://www."+MyBannerLinks[banner]
}function ShowBanners()
{ if (document.images)
{ banner++
if (banner==MyBanners.length) {
banner=0}
document.ChangeBanner.src=MyBanners[banner]
setTimeout("ShowBanners()",5000)
}
}
</script>
<body onload="ShowBanners()">
<center>
<a href="javascript: ShowLinks()">
<img src="banner1.jpg" width="900" height="120" name="ChangeBanner"/></a>
</center>
</body>
</html>
Output :
Click Banner Links to see the above JavaScript in action
❖ Slideshow
<html >
<head>
<script language=”Javascript”>
MySlides=new Array(‘banner1.jpg’,’banner2.jpg’,’banner3.jpg’,’banner4.jpg’)
Slide=0
function ShowSlides(SlideNumber){
{ Slide=Slide+SlideNumber
if (Slide>MySlides.length-1){
Slide=0
}
if (Slide<0) {
Slide=MySlides.length-1
}
document.DisplaySlide.src=MySlides[Slide]
}
}
</script>
</head>
<body>
<P align=”center”><img src=”banner1.jpg” name=”DisplaySlide” width=”900″
height=”120″ /><p>
<center>
<table border=0>
<tr>
<td align=center>
<input type=”button” value=”Back” onclick=”ShowSlides(-1)”>
<input type=”button” value=”Forward” onclick=”ShowSlides(1)”>
</td>
</tr>
</table>
</center>
</body>
</html>