SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
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

PDF
Spring Boot
PPTX
Http protocol
PPTX
SOAP - Simple Object Access Protocol
PPTX
Cookies and sessions
PPTX
Vulnerabilities in modern web applications
PPT
Security attacks
PDF
Web Services PHP Tutorial
PPTX
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
Spring Boot
Http protocol
SOAP - Simple Object Access Protocol
Cookies and sessions
Vulnerabilities in modern web applications
Security attacks
Web Services PHP Tutorial
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...

What's hot (20)

PPTX
Introduction XSS
PPTX
Oracle REST Data Services Best Practices/ Overview
PPT
Introduction to the Web API
PPTX
HTTP request and response
PPTX
Web Database
PDF
Introduction to OpenID Connect
PPTX
Lecture 5: Client Side Programming 1
PDF
Java Course 8: I/O, Files and Streams
PPTX
Basic web security model
PPT
PHP - Introduction to PHP AJAX
PDF
SOAP vs REST
PDF
Injecting Security into vulnerable web apps at Runtime
PPTX
SQLite - Overview
PDF
Introduction to Apache Tomcat 7 Presentation
PPT
Cookies and sessions
PDF
Criando e consumindo webservice REST com PHP e JSON
PDF
PUC SE Day 2019 - SpringBoot
PPTX
Web services SOAP
PDF
Penetration testing web application web application (in) security
Introduction XSS
Oracle REST Data Services Best Practices/ Overview
Introduction to the Web API
HTTP request and response
Web Database
Introduction to OpenID Connect
Lecture 5: Client Side Programming 1
Java Course 8: I/O, Files and Streams
Basic web security model
PHP - Introduction to PHP AJAX
SOAP vs REST
Injecting Security into vulnerable web apps at Runtime
SQLite - Overview
Introduction to Apache Tomcat 7 Presentation
Cookies and sessions
Criando e consumindo webservice REST com PHP e JSON
PUC SE Day 2019 - SpringBoot
Web services SOAP
Penetration testing web application web application (in) security
Ad

Viewers also liked (13)

DOC
Internet programming lab manual
PDF
Tutorial PHP and Dreamweaver CS3
PDF
Java lab-manual
DOCX
Java programming lab_manual_by_rohit_jaiswar
PDF
Internet programming lecture 1
PDF
Java Lab Manual
PDF
Java programming lab manual
PDF
66781291 java-lab-manual
PPT
Beginners PHP Tutorial
PDF
Web programming manual
PDF
Asp.net Lab manual
PPT
Introduction to PHP
Internet programming lab manual
Tutorial PHP and Dreamweaver CS3
Java lab-manual
Java programming lab_manual_by_rohit_jaiswar
Internet programming lecture 1
Java Lab Manual
Java programming lab manual
66781291 java-lab-manual
Beginners PHP Tutorial
Web programming manual
Asp.net Lab manual
Introduction to PHP
Ad

Similar to Webdesing lab part-b__java_script_ (20)

PPSX
Javascript variables and datatypes
PPTX
JavaScript / Web Engineering / Web Development / html + css + js/presentation
PDF
2 coding101 fewd_lesson2_programming_overview 20210105
PPT
Javascript
PPTX
Javascript 101
PPTX
Unit2wt
PPTX
Unit2wt
PPTX
Variables 2
PPTX
FYBSC IT Web Programming Unit III Core Javascript
PDF
1 coding101 fewd_lesson1_coding_quickstart 20210105
PPTX
BITM3730 10-17.pptx
PDF
PPT
Code
PPTX
Javascript comparison and logical operators 2
PPT
JavaScript
PDF
WEEK 1 -- DAY 1_20240119_220354_0000.pdf
PPT
JavaScript Functions
PDF
Intro to javascript (5:2)
PPT
Java script
PPT
Introduction to java script Lecture 4.ppt
Javascript variables and datatypes
JavaScript / Web Engineering / Web Development / html + css + js/presentation
2 coding101 fewd_lesson2_programming_overview 20210105
Javascript
Javascript 101
Unit2wt
Unit2wt
Variables 2
FYBSC IT Web Programming Unit III Core Javascript
1 coding101 fewd_lesson1_coding_quickstart 20210105
BITM3730 10-17.pptx
Code
Javascript comparison and logical operators 2
JavaScript
WEEK 1 -- DAY 1_20240119_220354_0000.pdf
JavaScript Functions
Intro to javascript (5:2)
Java script
Introduction to java script Lecture 4.ppt

Recently uploaded (20)

PPTX
Welding lecture in detail for understanding
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
bas. eng. economics group 4 presentation 1.pptx
DOCX
573137875-Attendance-Management-System-original
PPTX
Lecture Notes Electrical Wiring System Components
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
additive manufacturing of ss316l using mig welding
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Well-logging-methods_new................
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Digital Logic Computer Design lecture notes
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
composite construction of structures.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Welding lecture in detail for understanding
Mechanical Engineering MATERIALS Selection
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
bas. eng. economics group 4 presentation 1.pptx
573137875-Attendance-Management-System-original
Lecture Notes Electrical Wiring System Components
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
additive manufacturing of ss316l using mig welding
CYBER-CRIMES AND SECURITY A guide to understanding
Well-logging-methods_new................
Automation-in-Manufacturing-Chapter-Introduction.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Digital Logic Computer Design lecture notes
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
composite construction of structures.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf

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