1.
SQUARE, SQUARE ROOT, CUBE AND COMPLEMENTS
Program Coding:
<html>
<body>
<script language="javascript">
var i;
var inp=parseInt(prompt("enter the end range value","3"));
[Link]("no"+"   "+"square"+"   "+"squareroot"+"   "+
"cube"+"   "+"complement "+"<br>");
for(i=1;i<=inp;i++){
var sq=i*i;
var srt=[Link]([Link](i));
var cu=i*i*i;
var comp=(-i);
[Link](i+"      "+sq+"       
    "+srt+"            &
nbsp         "+cu+"      &nb
sp  "+comp+"<br>");
}
</script>
</body>
</html>
Output:
2. CALCULATOR
Program Coding:
<html>
<head>
<title> JavaScript Calculator </title>
<style>
h1 {
text-align: center;
padding: 23px;
background-color: skyblue;
color: white;
}
#clear{
width: 270px;
border: 3px solid gray;
border-radius: 3px;
padding: 20px;
background-color: red;
}
.formstyle
{
width: 300px;
height: 530px;
margin: auto;
border: 3px solid skyblue;
border-radius: 5px;
padding: 20px;
}
input
{
width: 20px;
background-color: green;
color: white;
border: 3px solid gray;
border-radius: 5px;
padding: 26px;
margin: 5px;
font-size: 15px;
}
#calc{
width: 250px;
border: 5px solid black;
border-radius: 3px;
padding: 20px;
margin: auto;
}
</style>
</head>
<body>
<h1> Calculator Program in JavaScript </h1>
<div class= "formstyle">
<form name = "form1">
<!-- This input box shows the button pressed by the user in calculator. -->
<input id = "calc" type ="text" name = "answer"> <br> <br>
<!-- Display the calculator button on the screen. -->
<!-- onclick() function display the number prsses by the user. -->
<input type = "button" value = "1" onclick = "[Link] += '1' ">
<input type = "button" value = "2" onclick = "[Link] += '2' ">
<input type = "button" value = "3" onclick = "[Link] += '3' ">
<input type = "button" value = "+" onclick = "[Link] += '+' ">
<br> <br>
<input type = "button" value = "4" onclick = "[Link] += '4' ">
<input type = "button" value = "5" onclick = "[Link] += '5' ">
<input type = "button" value = "6" onclick = "[Link] += '6' ">
<input type = "button" value = "-" onclick = "[Link] += '-' ">
<br> <br>
<input type = "button" value = "7" onclick = "[Link] += '7' ">
<input type = "button" value = "8" onclick = "[Link] += '8' ">
<input type = "button" value = "9" onclick = "[Link] += '9' ">
<input type = "button" value = "*" onclick = "[Link] += '*' ">
<br> <br>
<input type = "button" value = "/" onclick = "[Link] += '/' ">
<input type = "button" value = "0" onclick = "[Link] += '0' ">
<input type = "button" value = "." onclick = "[Link] += '.' ">
<!-- When we click on the '=' button, the onclick() shows the sum results on the calculator screen. -->
<input type = "button" value = "=" onclick = "[Link] = eval([Link]) ">
<br>
<!-- Display the Cancel button and erase all data entered by the user. -->
<input type = "button" value = "Clear All" onclick = "[Link] = ' ' " id= "clear" >
<br>
</form>
</div>
</body>
</html>
Output:
3. SORT NUMBER AND STRING
Program Coding:
Number:
<html>
<body>
<script>
// Declare and initialize original array
var marks = [12, 25, 31, 23, 75, 81, 10];
// Print Before Sorting Array
[Link]("Original Array</br>");
[Link](marks);
[Link]("</br>");
// Call sort function
[Link]();
[Link]("</br>After Sorting in Ascending Order</br>");
// Print Sorted Numeric Array
[Link](marks);
</script>
</body>
</html>
String:
<html>
<head>
<body>
<h2>Sort strings using for loop in JavaScript</h2>
<script>
function sortString(strArray) {
var i = 0;
var j;
while (i < [Link]) {
j = i + 1;
while (j < [Link]) {
if (strArray[j] < strArray[i]) {
var tempStr = strArray[i];
strArray[i] = strArray[j];
strArray[j] = tempStr;
}
j++;
}
i++;
}
}
var sortArray = ['Karthik', 'Saideep', 'Balu', 'Shweta', 'Divya', 'Bhanu'];
[Link]("Original Array of strings</br>");
[Link](sortArray);
[Link]("</br>");
sortString(sortArray);
[Link]("</br>Array of strings After sorting</br>");
[Link](sortArray);
</script>
</body>
</html>
Output:
Number:
String:
4. HIT COUNTER
Program Coding:
<html>
<head>
<title>Document</title>
</head>
<body>
<div>
<p>The number of visitors is : <span id="cntr">0</span></p>
</div>
<script>
function counter_fn() {
var counter = [Link]("cntr");
var count = 0;
count = parseInt([Link]);
count = count + 1;
[Link] = count;
}
[Link] = counter_fn;
</script>
</body>
</html>
Output:
5. EMAIL ID VALIDATION
Program Coding:
[Link]
<html>
<body onload="[Link]()">
<div class="mail">
<center><h2>Input an email address</h2></center>
<form name="form1" action="#">
<center><input type="text" name="text1" /></center>
<class="validate">
<center> <input type="submit" name="validate" value="Validate"
onclick="ValidateEmail(document.form1.text1)"
/></center>
</form>
</div>
<script src="[Link]"></script>
</body>
</html>
[Link]
function ValidateEmail(inputText)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if([Link](mailformat))
{
alert("Valid email address!");
[Link]();
return true;
}
else
{
alert("You have entered an invalid email address!");
[Link]();
return false;
}
}
Output:
6. SCROLL TEXT ON STATUS BAR
Program Coding:
<html>
<head>
<center>SCROLL TEXT ON STATUS BAR</center>
<script language="JavaScript">
var count=0;
var delay=250;
var text="WELCOME TO CHENNAI";
function scroll()
{
[Link]=[Link](count,[Link])+[Link](0,count)
if(count<[Link])
count ++;
else
count=0;
setTimeout("scroll()",delay);
}
</script>
</head>
<body onload="scroll()";>
</body>
</html>
Output:
7. CHOICE LIST
Program Coding:
<html>
<head>
<title>McDonalds</title>
<script language="JavaScript">
var m;
function pick(F1)
{
var z=" ";
for(j=0;j<3;j++)
{
for(i=0;i<[Link][j].length;i++)
{
if([Link][j][i].selected)
{
var y=[Link][j].options[i].value;
z=z+"\n"+y;
[Link][3].value=z;
}
}
}
m=z;
}
function clr(F1)
{
[Link][3].value=" ";
}
</script>
</head>
<body bgcolor="#00ffff">
<h2><font color="blue" size="20"><center>Welcome to the world Famous Fast Food center
</font><br>
<font coulor="red" size="10">Mc Donalds!</center></font></h2>
<form name="F1">
<form size="+2">
Select the menu items of ur choice:</font><br><br>
<table>
<tr valign =top><td>
<font size="+1">
Major dishes:</font><br>
<select name="s1" MULTIPLE onBlur="pick([Link])">
<option value="Mc burger->Rs.80" selected>mc burger
<option value="fish fullets->Rs.70" >fish fullets
<option value=" burger->Rs.60" > burger
<option value="veg burger->Rs.50" >veg burger
</select>
<br><br>
</td><td>
<font size="+1">
Miscellaneous:</font><br>
</b></td>
</tr></table>
<font size="+1">
Stock:</font><br>
<select name="s2"MULTIPLE onBlur="pick([Link])">
<option value="Dining Table & Chairs->500"selected>Dining Table & Chairs
<option value="Tissues->1000">Tissues
<option value="Menu Cards->30">Menu Cards
<option value="Tool Bowl->50">Tool Bowl
</select>
<br><br></td>
</table>
<select name="s3" onBlur="pick([Link])">
<option value="Milkshakes->Rs.35"selected>Milkshakes
<option value="Soft drinks->Rs.20">Soft drinks
<option value="Softy->Rs.30">Softy
</select>
<br><br></td><td>
<th><font size="6">The items selected form the menu are:</font></th>
<table>
<tr valign=top><td>
<textarea name="TAI" rows=10 cols=50>
</textarea ><br><br></td>
<td><br>
<br><br>
<b>
<input type="button" value="submit">
<input type="button" value="clear" onclick="clr([Link])">
</form>
</body>
</html>
Output:
8. DIGITAL CLOCK
Program Coding:
<html>
<head>
<title>DIGITAL CLOCK</title>
<script language="JavaScript">
function nextone()
{
now=new Date();
hours=[Link]();
mins=[Link]();
sec=[Link]();
if(mins<10)
time=" "+hours+ ":0"+mins;
else
time=" "+hours+":"+mins;
if(sec<10)
time+=":0"+sec;
else
time+=":"+sec;
[Link]=time;
setTimeout("nextone();4",100);
}
setTimeout("nextone();",100);
</script>
</head>
<body bgcolor="#00fff">
<font size="25"><center>
Digital clock</font>
<form name="timeform">
<font size=8>
current time=<input type="text" name="timeclock" size="10">
</font>
</form>
</body>
</html>
Output:
9. MOUSE EVENTS
Program Coding:
<html>
<head>
<script language="Javascript">
function bigImg(x)
{
[Link]="120px";
[Link]="120px";
}
function normalImg(x)
{
[Link]="32px";
[Link]="32px";
}
</script>
</head>
<body>
<img src=" C:\Users\Public\Pictures\Sample Pictures\[Link]" onmouseover="bigImg(this)"
onmouseout="normalImg(this)" border="0" width="32" height="32">
</body>
</html>
Output:
Onmouseover
Onmouseout
10. BUTTON WITH IMAGE
Program Coding:
<html>
<head>
<style>
#image
{
display: none;
}
#image1
{
display: none;
}
#image2
{
display: none;
}
</style>
</head>
<body background="E:\Picture\[Link]">
<div><img id="image" src="E:\Picture\images (1).jfif"/></div>
<button type="button"onclick="show()" id="btnID">Show Image1</button>
<div><img id="image1" src="E:\Picture\[Link]"/></div>
<button type="button"onclick="show1()" id="btnID1">Show Image2</button>
<div><img id="image2" src="E:\Picture\[Link]"/></div>
<button type="button"onclick="show2()" id="btnID2">Show Image3</button>
<script>
function show()
{
[Link]('image').[Link] = "block";
[Link]('btnID').[Link] = "none";
}
function show1()
{
[Link]('image1').[Link] = "block";
[Link]('btnID1').[Link] = "none";
}
function show2()
{
[Link]('image2').[Link] = "block";
[Link]('btnID2').[Link] = "none";
}
</script>
</body>
</html>
Output:
11. FRAMES WITH SEARCH ENGINE
Program Coding:
[Link]
<html>
<head>
<title>VB Script frames</title>
</head>
<frameset cols="30%,70%">
<frame src="[Link]" name="one">
<frame src="[Link]" name="two">
</frameset>
</html>
[Link]
<html>
<head>
<title>vbscript</title>
</head>
<script language="vbscript">
function result(A)
if A=1 then
[Link]="[Link]"
end if
if A=2 then
[Link]="[Link]"
end if
if A=3 then
[Link]="[Link]"
end if
end function
</script>
<body BGCOLOR="#00ffff">
<form>
<div align="center">
<input type="radio" name=choice onclick="result(1)">Yahoo<br>
<input type="radio" name=choice onclick="result(2)">Altavista<br>
<input type="radio" name=choice onclick="result(3)">Infoseek<br>
</div>
</form>
</body>
</html>
[Link]
<html>
<head>
<title>Hi</title>
</head>
<body bgcolor="blue">
<h1><center>Welcome You All!!!!!</center></h1>
</body>
</html>
[Link]
<html>
<head>
<title>yahoo</title>
</head>
<body bgcolor="yellow">
<h1><center><a href="[Link] page</a></center></h1>
</body>
</html>
[Link]
<html>
<head>
<title>yahoo</title>
</head>
<body bgcolor="green">
<h1><center><a href="[Link]
</body>
</html>
[Link]
<html>
<head>
<title>yahoo</title>
</head>
<body bgcolor="pink">
<h1><center><a href="[Link]
</body>
</html>
Output:
12. FORM VALIDATION
Program Coding:
<html>
<head>
<title>Registration Form</title>
<script type="text/javascript">
function validate_form() {
if ([Link].emp_name.value == "")
{
alert("Please fill in the 'Your Employee Name' box.");
return false;
}
if ([Link] == "") {
alert("Enter Employee Number");
return false;
}
alert("sucessfully Submitted");
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/).test([Link].email_id.value)) {
alert("You have entered an invalid email address!")
return (false)
}
}
function isNumberKey(evt) {
var charCode = ([Link]) ? [Link] : [Link];
if (charCode != 46 && charCode > 31 &&
(charCode < 48 || charCode > 57)) {
alert("Enter Number");
return false;
}
return true;
}
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="emp" action="" onsubmit="return validate_form();" method="post">
<table align="center" width=40% width="100%" cellspacing="2" cellpadding="2" border="5">
<tr>
<td colspan="2" align="center"><b>Employee Registration Form.</b></td>
</tr>
<tr>
<td align="left" valign="top" width="41%">Employee Name<span style="color:red">*</span></td>
<td width="57%"><input type="text" value="" name="emp_name" size="24"></td>
</tr>
<tr>
<td align="left" valign="top" width="41%">Employee Number<span style="color:red">*</span></td>
<td width="57%">
<input type="text" value="" name="num" onkeypress="return isNumberKey(event)" size="24"></td>
</tr>
<tr>
<td align="left" valign="top" width="41%">Address</td>
<td width="57%"><textarea rows="4" maxlen="200" name="S2" cols="20"></textarea></td>
</tr <tr>
<td align="left" valign="top" width="41%">Contact Number</td>
<td width="57%">
<input type="text" value="" onkeypress="return isNumberKey(event)" name="txtFName1" size="24"></td>
</tr>
<tr>
<td align="left" valign="top" width="41%">Job Location</td>
<td width="57%"><select name="mydropdown">
<option value="Default">Default</option>
<option value="Chennai">Chennai</option>
<option value="Bangalore">Bangalore</option>
<option value="Chennai">Pune</option>
<option value="Bangalore">Mysore</option>
<option value="Chennai">Chandigarh</option>
</select></td>
</tr>
<tr>
<td align="left" valign="top" width="41%">Designation</td>
<td width="57%">
<select name="mydropdown">
<option value="Default">Default</option>
<option value="Systems Engineer">Systems Engineer</option>
<option value="Senior Systems Engineer">Senior Systems Engineer</option>
<option value="Technology Analyst">Technology Analyst</option>
<option value="Technology Lead">Technology Lead</option>
<option value="Project Manager">Project Manager</option>
</select></td>
</tr>
<tr>
<td align="left" valign="top" width="41%">Email<span style="color:red">*</span></td>
<td width="57%">
<input type="text" value="" name="email_id" size="24"></td>
</tr>
<tr>
<td colspan="2">
<p align="center">
<input type="submit" value=" Submit"
name="B4">
<input type="reset" value=" Reset All " name="B5"></td>
</tr>
</table>
</form>
</body>
</html>
Output: