SlideShare a Scribd company logo
Part-B Web Design Lab JavaScript 
WEB DESIGN LAB PART-B 
JAVA SCRIPT LABORATORY MANUAL 
FOR 3RD SEM IS AND CS 
(2011-2012) 
BY 
MISS. SAVITHA R 
LECTURER 
INFORMATION SCIENCE DEPTATMENT 
GOVERNMENT POLYTECHNIC 
GULBARGA 
FOR ANY FEEDBACK CONTACT TO 
EMAIL: savitharamu@gmail.com 
GOVT.POLYTECHNIC BIJAPUR 1
Part-B Web Design Lab JavaScript 
PROGRAM 1 
JAVA SCRIPT TO PERFORM ALL ARITHMATIC OPERATION 
<html> 
<head> 
<title> Arithmatic Operation </title> 
<script type="text/javascript"> 
var n1,n2,r; 
function add() 
{ 
n1=document.myform.n1.value; 
n2=document.myform.n2.value; 
n1=parseFloat(n1); 
n2=parseFloat(n2); 
r=n1+n2; 
document.myform.result.value=r; 
} 
function sub() 
{ 
n1=document.myform.n1.value; 
n2=document.myform.n2.value; 
n1=parseFloat(n1); 
n2=parseFloat(n2); 
r=n1-n2; 
document.myform.result.value=r; 
} 
function mul() 
{ 
n1=document.myform.n1.value; 
n2=document.myform.n2.value; 
n1=parseFloat(n1); 
n2=parseFloat(n2); 
r=n1*n2; 
document.myform.result.value=r; 
} 
function divide() 
{ 
n1=document.myform.n1.value; 
n2=document.myform.n2.value; 
n1=parseFloat(n1); 
n2=parseFloat(n2); 
r=n1/n2; 
document.myform.result.value=r; 
} 
GOVT.POLYTECHNIC BIJAPUR 2
Part-B Web Design Lab JavaScript 
</script> </head> 
<body> 
<form name="myform"> 
<h1 align="center"> Arithmatic Operations</h1> 
<hr color="red"> 
<center><u>Enter a number in each text box </u><br><br> 
Number 1:<input type="text" name="n1" value=""> <br><br> 
Number 2:<input type="text" name="n2" value=""> <br><br> 
<input type="button" value="Add" onClick="add()"> 
<input type="button" value="Subtract" onClick="sub()"> 
<input type="button" value="Multiply" onClick="mul()" > 
<input type="button" value="Divide" onClick="divide()"><br><br> 
<font color="red">Result is: 
<input type="text" name="result" value=""></center></font> 
</form> 
</body> 
</html> 
OUTPUT 
GOVT.POLYTECHNIC BIJAPUR 3
Part-B Web Design Lab JavaScript 
GOVT.POLYTECHNIC BIJAPUR 4
Part-B Web Design Lab JavaScript 
PROGRAM 2 
JAVA SCRIPT TO CHECK WHETHER A GIVEN NUMBER IS PRIME OR NOT 
<html> 
<head> <title> To check for a prime number </title> 
<script type="text/javascript"> 
function p() 
{ 
var n,i,flag=true; 
n=document.myform.n.value; 
n=parseInt(n) 
for(i=2;i<=n-1;i++) 
if(n%i==0) 
{ 
flag=false; 
break; 
} 
if(flag==true) 
alert(n + " is prime"); 
else 
alert(n + " is not prime"); 
} 
</script></head> 
<body> 
<center> 
<h1> To check whether a given number is prime or not </h1> 
<hr color="red"> 
<form name="myform"> 
Enter the number: <input type="text" name=n value=""><br><br> 
<input type="button" value="Check" onClick="p()"><br> 
</center> 
</form> 
</body> 
</html> 
GOVT.POLYTECHNIC BIJAPUR 5
Part-B Web Design Lab JavaScript 
OUTPUT 
GOVT.POLYTECHNIC BIJAPUR 6
Part-B Web Design Lab JavaScript 
PROGRAM 3 
JAVA SCRIPT TO SEARCH AN ELEMENT IN AN ARRAY OF SIZE “N” 
<html> 
<head> 
<script type="text/javascript"> 
function show_prompt() 
{ 
var n=document.frm.text1.value; 
if( n == "") 
{ 
alert("Please enter the array size"); 
} 
else 
{ 
var a=new Array(); 
var temp; 
for(i=0;i<n;i++) 
{ 
var num=prompt("Please enter a number"," "); 
document.frm.arrayTxt.value=document.frm.arrayTxt.value+num+"n"; 
a[i]=parseInt(num); 
} 
var flag=0; 
var search=prompt("Enter the element to be searched ",""); 
for(i=0;i<n;i++) 
if(a[i]==search) 
{ 
flag=1; 
p=i+1; 
} 
if(flag==1) 
alert("Element " + search + " found at position " +p); 
else 
alert("Sorry!, Element " + search + " not found "); 
document.frm.text1.value=""; 
document.frm.arrayTxt.value=""; 
} 
} 
</script> 
</head> 
<body> 
GOVT.POLYTECHNIC BIJAPUR 7
Part-B Web Design Lab JavaScript 
<form name="frm"> 
<center> 
<h3>To find an element in a given array </h3> 
<hr color="red"> 
Enter the array size : <input type="text" name="text1"><br><br> 
<input type="button" onclick="show_prompt()" value="Submit"> <br><br> 
<textarea name="arrayTxt" rows="10" cols="4"></textarea><br> 
</center> 
</form></body></html> 
OUTPUT 
GOVT.POLYTECHNIC BIJAPUR 8
Part-B Web Design Lab JavaScript 
GOVT.POLYTECHNIC BIJAPUR 9
Part-B Web Design Lab JavaScript 
PROGRAM 4 
JAVA SCRIPT TO ILLUSTRATE A SUBROUTINE. 
<html> 
<head> 
<script type="text/javascript"> 
function myfunction() 
{ 
document.write("<h1 align=center> <font color=red> Hello !!! This Message 
is From The SubRoutine </font> </h1>"); 
} 
</script> 
</head> 
<body> 
<h1 align="center"> Subroutine Example </h1> 
<hr color="red"> 
<center> 
<form> 
<input type="button" value="Cal Subroutine " onClick="myfunction()"); 
</from> 
</center> 
</body> 
</html> 
OUTPUT 
GOVT.POLYTECHNIC BIJAPUR 10
Part-B Web Design Lab JavaScript 
PROGRAM 5 
JAVA SCRIPT TO COMPUTE THE GCD OF 2 NUMBERS USING FUNCTION. 
<html> 
<head> 
<script type="text/javascript"> 
function gcd() 
{ 
var x,y; 
x=parseInt(document.myform.n1.value); 
y=parseInt(document.myform.n2.value); 
while(x!=y) 
{ 
if(x>y) 
x=x-y; 
else 
y=y-x; 
} 
document.myform.result.value=x; 
} 
</script> 
</head> 
<body> 
<h1 align="center"> Program to calculate gcd of two numbers </h1> 
<hr color="red"> 
<center> 
Enter two numbers : 
<form name="myform"> 
Number 1 : <input type="text" name="n1" value=""> <br> <br> 
Number 2 : <input type="text" name="n2" value=""> <br> <br> 
<input type="button" value="Get GCD" onClick="gcd()"> <br> <br> 
GCD is : <input type="text" name="result" value=""> 
</form> 
</body> 
</html> 
GOVT.POLYTECHNIC BIJAPUR 11
Part-B Web Design Lab JavaScript 
OUTPUT 
GOVT.POLYTECHNIC BIJAPUR 12
Part-B Web Design Lab JavaScript 
PROGRAM 6 
JAVA SCRIPT TO FIND THE SECOND LARGEST NUMBER IN AN ARRAY. 
<html> 
<head> 
<script type="text/javascript"> 
function show_prompt() 
{ 
var n=document.frm.text1.value; 
if( n == "") 
{ 
alert("Please enter the array size"); 
} 
else 
{ 
var a=new Array(); 
var temp; 
for(i=0;i<n;i++) 
{ 
var num=prompt("Please enter a number"," "); 
document.frm.arrayTxt.value=document.frm.arrayTxt.value+num+"n"; 
a[i]=parseInt(num); 
} 
var large=a[0]; for(i=1;i<n;i++) if(a[i]>large) large=a[i]; 
var slarge=a[0]; for(i=1;i<n;i++) if(a[i]>slarge && a[i]!=large) 
slarge=a[i]; 
alert("The second largest element in the given array is "+slarge); 
document.frm.text1.value=""; 
document.frm.arrayTxt.value=""; 
} 
} 
</script> 
</head> 
<body> 
<form name="frm"> 
<center> 
<h1>To find second largest element in a given array </h1> 
<hr color=”red”> 
Enter the array size : <input type="text" name="text1"><br><br> 
<input type="button" onClick="show_prompt()" value="Submit"> <br><br> 
<textarea name="arrayTxt" rows="10" cols="4"></textarea><br> 
GOVT.POLYTECHNIC BIJAPUR 13
Part-B Web Design Lab JavaScript 
</center> 
</form> 
</body> 
</html> 
OUTPUT 
. 
GOVT.POLYTECHNIC BIJAPUR 14
Part-B Web Design Lab JavaScript 
PROGRAM 7 
JAVA SCRIPT TO CHECK WHETHER THE GIVEN INTEGER IS PALINDROME 
OR NOT 
<html> 
<head> 
<script type="text/javascript"> 
function isPalindrome() 
{ 
var num=document.frm.text1.value; 
if(num == "") 
{ 
alert("Please enter the number"); 
} 
else 
{ 
var digit; 
var rev = 0; 
var n = num; 
while (num!=0) 
{ 
digit = num% 10; 
rev = (rev * 10) + digit; 
num = num / 10; 
num = parseInt(num); 
} 
if( n == rev) 
alert(" Integer is palindrome "); 
else 
alert(" Integer is not palindrome "); 
document.frm.text1.value=""; 
} 
} 
</script> 
</head> 
<body> 
<form name="frm"> 
<h1 align="center">To check whether a number is palindrome or not</h1> 
<hr color="red"> 
<center> 
Enter a number: 
<input type="text" name="text1"> <br><br> 
<input type="button" value="Check Palindrome" onclick="isPalindrome()"> 
GOVT.POLYTECHNIC BIJAPUR 15
Part-B Web Design Lab JavaScript 
</center> 
</form> 
</body> 
</html> 
OUTPUT 
GOVT.POLYTECHNIC BIJAPUR 16
Part-B Web Design Lab JavaScript 
PROGRAM 8 
JAVA SCRIPT TO ILLUSTRATE DIFFERENT IN-BUILT STRING FUNCTIONS. 
<html> 
<body> 
<script type="text/javascript"> 
var str="Hello World"; 
document.write("<center>"); 
document.write("<h1> Example for String Functions </h1> "); 
document.write("<hr color=red>"); 
document.write(str.big()+"<br>"); 
document.write(str.small()+"<br>"); 
document.write(str.bold()+"<br>"); 
document.write(str.italics()+"<br>"); 
document.write(str.fixed()+"<br>"); 
document.write(str.strike()+"<br>"); 
document.write(str.sup()+"<br>"); 
document.write(str.sub()+"<br>"); 
document.write(str.blink()+"<br>"); 
document.write(str.link("p1.html")+"<br>"); 
document.write(str.fontcolor("green")+"<br>"); 
document.write(str.fontsize(6)+"<br>"); 
document.write("</center>"); 
</script> 
</body> 
</html> 
OUTPUT 
GOVT.POLYTECHNIC BIJAPUR 17

More Related Content

Viewers also liked

Viewers also liked (12)

Internet programming lab manual
Internet programming lab manualInternet programming lab manual
Internet programming lab manual
 
Tutorial PHP and Dreamweaver CS3
Tutorial PHP and Dreamweaver CS3Tutorial PHP and Dreamweaver CS3
Tutorial PHP and Dreamweaver CS3
 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswar
 
Internet programming lecture 1
Internet programming lecture 1Internet programming lecture 1
Internet programming lecture 1
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
 
Java lab 2
Java lab 2Java lab 2
Java lab 2
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manual
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
 
Asp.net Lab manual
Asp.net Lab manualAsp.net Lab manual
Asp.net Lab manual
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

Similar to Webdesing lab part-b__java_script_ (20)

JAVASCRIPT PROGRAM.pdf
JAVASCRIPT PROGRAM.pdfJAVASCRIPT PROGRAM.pdf
JAVASCRIPT PROGRAM.pdf
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript Operators
JavaScript OperatorsJavaScript Operators
JavaScript Operators
 
Javascript
JavascriptJavascript
Javascript
 
Implementation of GUI Framework part3
Implementation of GUI Framework part3Implementation of GUI Framework part3
Implementation of GUI Framework part3
 
phptut2
phptut2phptut2
phptut2
 
phptut2
phptut2phptut2
phptut2
 
phptut2
phptut2phptut2
phptut2
 
phptut2
phptut2phptut2
phptut2
 
Lab manual asp.net
Lab manual asp.netLab manual asp.net
Lab manual asp.net
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
 
JavaScript Training
JavaScript TrainingJavaScript Training
JavaScript Training
 
1cst
1cst1cst
1cst
 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12
 
Svelte JS introduction
Svelte JS introductionSvelte JS introduction
Svelte JS introduction
 
Java script
Java scriptJava script
Java script
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
 
PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014
 
Web lab programs
Web lab programsWeb lab programs
Web lab programs
 
Client sidescripting javascript
Client sidescripting javascriptClient sidescripting javascript
Client sidescripting javascript
 

Recently uploaded

Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxwendy cai
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdfAhmedHussein950959
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfKamal Acharya
 
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringKIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringDr. Radhey Shyam
 
Electrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineElectrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineJulioCesarSalazarHer1
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdfKamal Acharya
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxR&R Consult
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfPipe Restoration Solutions
 
Top 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering ScientistTop 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering Scientistgettygaming1
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectRased Khan
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGKOUSTAV SARKAR
 
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringC Sai Kiran
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfKamal Acharya
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfKamal Acharya
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopEmre Günaydın
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsAtif Razi
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturingssuser0811ec
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdfKamal Acharya
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...Amil baba
 

Recently uploaded (20)

Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
 
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringKIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
 
Electrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineElectrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission line
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Top 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering ScientistTop 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering Scientist
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
 
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturing
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdf
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
 

Webdesing lab part-b__java_script_

  • 1. Part-B Web Design Lab JavaScript WEB DESIGN LAB PART-B JAVA SCRIPT LABORATORY MANUAL FOR 3RD SEM IS AND CS (2011-2012) BY MISS. SAVITHA R LECTURER INFORMATION SCIENCE DEPTATMENT GOVERNMENT POLYTECHNIC GULBARGA FOR ANY FEEDBACK CONTACT TO EMAIL: savitharamu@gmail.com GOVT.POLYTECHNIC BIJAPUR 1
  • 2. Part-B Web Design Lab JavaScript PROGRAM 1 JAVA SCRIPT TO PERFORM ALL ARITHMATIC OPERATION <html> <head> <title> Arithmatic Operation </title> <script type="text/javascript"> var n1,n2,r; function add() { n1=document.myform.n1.value; n2=document.myform.n2.value; n1=parseFloat(n1); n2=parseFloat(n2); r=n1+n2; document.myform.result.value=r; } function sub() { n1=document.myform.n1.value; n2=document.myform.n2.value; n1=parseFloat(n1); n2=parseFloat(n2); r=n1-n2; document.myform.result.value=r; } function mul() { n1=document.myform.n1.value; n2=document.myform.n2.value; n1=parseFloat(n1); n2=parseFloat(n2); r=n1*n2; document.myform.result.value=r; } function divide() { n1=document.myform.n1.value; n2=document.myform.n2.value; n1=parseFloat(n1); n2=parseFloat(n2); r=n1/n2; document.myform.result.value=r; } GOVT.POLYTECHNIC BIJAPUR 2
  • 3. Part-B Web Design Lab JavaScript </script> </head> <body> <form name="myform"> <h1 align="center"> Arithmatic Operations</h1> <hr color="red"> <center><u>Enter a number in each text box </u><br><br> Number 1:<input type="text" name="n1" value=""> <br><br> Number 2:<input type="text" name="n2" value=""> <br><br> <input type="button" value="Add" onClick="add()"> <input type="button" value="Subtract" onClick="sub()"> <input type="button" value="Multiply" onClick="mul()" > <input type="button" value="Divide" onClick="divide()"><br><br> <font color="red">Result is: <input type="text" name="result" value=""></center></font> </form> </body> </html> OUTPUT GOVT.POLYTECHNIC BIJAPUR 3
  • 4. Part-B Web Design Lab JavaScript GOVT.POLYTECHNIC BIJAPUR 4
  • 5. Part-B Web Design Lab JavaScript PROGRAM 2 JAVA SCRIPT TO CHECK WHETHER A GIVEN NUMBER IS PRIME OR NOT <html> <head> <title> To check for a prime number </title> <script type="text/javascript"> function p() { var n,i,flag=true; n=document.myform.n.value; n=parseInt(n) for(i=2;i<=n-1;i++) if(n%i==0) { flag=false; break; } if(flag==true) alert(n + " is prime"); else alert(n + " is not prime"); } </script></head> <body> <center> <h1> To check whether a given number is prime or not </h1> <hr color="red"> <form name="myform"> Enter the number: <input type="text" name=n value=""><br><br> <input type="button" value="Check" onClick="p()"><br> </center> </form> </body> </html> GOVT.POLYTECHNIC BIJAPUR 5
  • 6. Part-B Web Design Lab JavaScript OUTPUT GOVT.POLYTECHNIC BIJAPUR 6
  • 7. Part-B Web Design Lab JavaScript PROGRAM 3 JAVA SCRIPT TO SEARCH AN ELEMENT IN AN ARRAY OF SIZE “N” <html> <head> <script type="text/javascript"> function show_prompt() { var n=document.frm.text1.value; if( n == "") { alert("Please enter the array size"); } else { var a=new Array(); var temp; for(i=0;i<n;i++) { var num=prompt("Please enter a number"," "); document.frm.arrayTxt.value=document.frm.arrayTxt.value+num+"n"; a[i]=parseInt(num); } var flag=0; var search=prompt("Enter the element to be searched ",""); for(i=0;i<n;i++) if(a[i]==search) { flag=1; p=i+1; } if(flag==1) alert("Element " + search + " found at position " +p); else alert("Sorry!, Element " + search + " not found "); document.frm.text1.value=""; document.frm.arrayTxt.value=""; } } </script> </head> <body> GOVT.POLYTECHNIC BIJAPUR 7
  • 8. Part-B Web Design Lab JavaScript <form name="frm"> <center> <h3>To find an element in a given array </h3> <hr color="red"> Enter the array size : <input type="text" name="text1"><br><br> <input type="button" onclick="show_prompt()" value="Submit"> <br><br> <textarea name="arrayTxt" rows="10" cols="4"></textarea><br> </center> </form></body></html> OUTPUT GOVT.POLYTECHNIC BIJAPUR 8
  • 9. Part-B Web Design Lab JavaScript GOVT.POLYTECHNIC BIJAPUR 9
  • 10. Part-B Web Design Lab JavaScript PROGRAM 4 JAVA SCRIPT TO ILLUSTRATE A SUBROUTINE. <html> <head> <script type="text/javascript"> function myfunction() { document.write("<h1 align=center> <font color=red> Hello !!! This Message is From The SubRoutine </font> </h1>"); } </script> </head> <body> <h1 align="center"> Subroutine Example </h1> <hr color="red"> <center> <form> <input type="button" value="Cal Subroutine " onClick="myfunction()"); </from> </center> </body> </html> OUTPUT GOVT.POLYTECHNIC BIJAPUR 10
  • 11. Part-B Web Design Lab JavaScript PROGRAM 5 JAVA SCRIPT TO COMPUTE THE GCD OF 2 NUMBERS USING FUNCTION. <html> <head> <script type="text/javascript"> function gcd() { var x,y; x=parseInt(document.myform.n1.value); y=parseInt(document.myform.n2.value); while(x!=y) { if(x>y) x=x-y; else y=y-x; } document.myform.result.value=x; } </script> </head> <body> <h1 align="center"> Program to calculate gcd of two numbers </h1> <hr color="red"> <center> Enter two numbers : <form name="myform"> Number 1 : <input type="text" name="n1" value=""> <br> <br> Number 2 : <input type="text" name="n2" value=""> <br> <br> <input type="button" value="Get GCD" onClick="gcd()"> <br> <br> GCD is : <input type="text" name="result" value=""> </form> </body> </html> GOVT.POLYTECHNIC BIJAPUR 11
  • 12. Part-B Web Design Lab JavaScript OUTPUT GOVT.POLYTECHNIC BIJAPUR 12
  • 13. Part-B Web Design Lab JavaScript PROGRAM 6 JAVA SCRIPT TO FIND THE SECOND LARGEST NUMBER IN AN ARRAY. <html> <head> <script type="text/javascript"> function show_prompt() { var n=document.frm.text1.value; if( n == "") { alert("Please enter the array size"); } else { var a=new Array(); var temp; for(i=0;i<n;i++) { var num=prompt("Please enter a number"," "); document.frm.arrayTxt.value=document.frm.arrayTxt.value+num+"n"; a[i]=parseInt(num); } var large=a[0]; for(i=1;i<n;i++) if(a[i]>large) large=a[i]; var slarge=a[0]; for(i=1;i<n;i++) if(a[i]>slarge && a[i]!=large) slarge=a[i]; alert("The second largest element in the given array is "+slarge); document.frm.text1.value=""; document.frm.arrayTxt.value=""; } } </script> </head> <body> <form name="frm"> <center> <h1>To find second largest element in a given array </h1> <hr color=”red”> Enter the array size : <input type="text" name="text1"><br><br> <input type="button" onClick="show_prompt()" value="Submit"> <br><br> <textarea name="arrayTxt" rows="10" cols="4"></textarea><br> GOVT.POLYTECHNIC BIJAPUR 13
  • 14. Part-B Web Design Lab JavaScript </center> </form> </body> </html> OUTPUT . GOVT.POLYTECHNIC BIJAPUR 14
  • 15. Part-B Web Design Lab JavaScript PROGRAM 7 JAVA SCRIPT TO CHECK WHETHER THE GIVEN INTEGER IS PALINDROME OR NOT <html> <head> <script type="text/javascript"> function isPalindrome() { var num=document.frm.text1.value; if(num == "") { alert("Please enter the number"); } else { var digit; var rev = 0; var n = num; while (num!=0) { digit = num% 10; rev = (rev * 10) + digit; num = num / 10; num = parseInt(num); } if( n == rev) alert(" Integer is palindrome "); else alert(" Integer is not palindrome "); document.frm.text1.value=""; } } </script> </head> <body> <form name="frm"> <h1 align="center">To check whether a number is palindrome or not</h1> <hr color="red"> <center> Enter a number: <input type="text" name="text1"> <br><br> <input type="button" value="Check Palindrome" onclick="isPalindrome()"> GOVT.POLYTECHNIC BIJAPUR 15
  • 16. Part-B Web Design Lab JavaScript </center> </form> </body> </html> OUTPUT GOVT.POLYTECHNIC BIJAPUR 16
  • 17. Part-B Web Design Lab JavaScript PROGRAM 8 JAVA SCRIPT TO ILLUSTRATE DIFFERENT IN-BUILT STRING FUNCTIONS. <html> <body> <script type="text/javascript"> var str="Hello World"; document.write("<center>"); document.write("<h1> Example for String Functions </h1> "); document.write("<hr color=red>"); document.write(str.big()+"<br>"); document.write(str.small()+"<br>"); document.write(str.bold()+"<br>"); document.write(str.italics()+"<br>"); document.write(str.fixed()+"<br>"); document.write(str.strike()+"<br>"); document.write(str.sup()+"<br>"); document.write(str.sub()+"<br>"); document.write(str.blink()+"<br>"); document.write(str.link("p1.html")+"<br>"); document.write(str.fontcolor("green")+"<br>"); document.write(str.fontsize(6)+"<br>"); document.write("</center>"); </script> </body> </html> OUTPUT GOVT.POLYTECHNIC BIJAPUR 17