Web Programs Part 2..
Web Programs Part 2..
Program:
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript</h1>
<script>
var number = prompt ("Enter a number to find Odd or Even ","Type
your number here");
if (number % 2 == 0)
{
alert ("The number entered is even.");
}
else
{
alert ("The number entered is odd.");
}
</script>
</body>
</html>
Output
Program no :14
Program:
<html>
<head>
</head>
<body>
<script>
var sum=0;
</script>
</body>
</html>
Output:
Program No: 15
Square Of Numbers
Aim: Create a user defined function square to find square of numbers from 1 to 10.
Program
<!DOCTYPE html>
<html>
<head>
margin: 0;
</style>
<script>
return y * y;
</script>
</head>
<body>
</body>
</html>
Output:
Program No:16
Program:
<html>
<head>
<script>
function login()
if(name!=null)
else
</script>
</head>
<body>
<center>
<form>
</form>
</center>
</body>
</html>
Output:
Program No:17
Form Validation
Aim: Create JavaScript code to validate a form created using HTML
Program:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Form Validation</title>
</head>
<body>
<h1>REGISTRATION FORM</h1>
<label for="name">Name:</label>
<p>
</p>
<p>
<label for="password">Password:</label>
</p>
<p>
</p>
</form>
<script>
function validateForm()
if (name == "")
isValid = false;
isValid = false;
isValid = false;
if (!agree)
isValid = false;
if(isValid)
</script>
</body>
</html>
Output:
Program No:18
Mouseclick Event
Aim: Write a javascript code to show Mouseclick Event.
Program:
<html>
<head>
<title>Mouseclickevent</title>
</head>
<body>
function clickevent()
document.write("Hello World");
</script>
<form>
</form>
</body>
</html>
OUTPUT:
Program No:19
Reverse A Number
Aim: Write a javascript code to Reverse a number.
Program:
<html>
<title>Reverse a number</title>
function rev_num()
var n= num;
while (n>0)
rem = n % 10;
n = Math.floor(n/10);
document.write("The given number is : " +num+ " <br/> The reversed number is : "
+rev+"\n");
</script>
<body onload="rev_num();">
<body>
</html>
Output:
Program No:20
Factorial
Aim: Write a javascript program to find the factorial of a numbers.
Program:
<html>
<head>
<script type="text/javascript">
function factorial()
var n,i,f=1;
n=prompt("Enter Number");
for(i=1;i<=n;i++)
f=f*i;
document.write("Factorial="+f);
</script>
</head>
<body>
<form>
</form>
</body>
</html>
OUTPUT:
Program No:21
External Files
Aim: Create a website to calculate sum of array using HTML, Javascript and CSS as separate external
files.
Program:
array.html
<html>
<body>
<script src="sum.js"></script>
</body>
</html>
style.css
body {
background-color: black;
}
h1 {
color: #000;
font-family: Arial, Helvetica, sans-serif;
}
sum.js
var number=[1,2,5,2];
var sum=0;
for(var i=0;i<number.length;i++)
{
sum+=number[i];
}
document.write(number);
document.write("<br>The sum of above numbers are:"+sum);
OUTPUT:
Program No:22
XML
Aim: Display an XML tree structure of a bookstore.
Program:
Bookstore.xml
<bookstore>
<book category="fiction">
<title>Harry Potter</title>
<author>J.K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="non-fiction">
<title>Introduction to XML</title>
<author>John Doe</author>
<year>2010</year>
<price>39.95</price>
</book>
</bookstore>
OUTPUT: