VI BCA-Web Programming - Lab Programs
VI BCA-Web Programming - Lab Programs
Lab Manual
<head>
<title> Count form elements </title>
<script type="text/javascript">
function countFormElements()
{
alert("the number of elements are :"+document.myForm.length);
}
</script>
</head>
<body bgcolor=cyan>
<h1 align=center>Counting Form Elements </h1>
<hr>
<form name="myForm" align=left>
1. Name :     <input type=text/> <br><br>
2. Password: <input type="password"/><br><br>
3. Address:  <textarea id="emailbody" cols=50 rows=10></textarea>
<br><br>
4. Sex:<input type=radio name=gender/>Male
<input type=radio name=gender/>Female<br><br>
5. Newsletter <input type=checkbox checked="checked"/><br><br>
<input type=button value="Send Message" onclick="countFormElements()" />
</form>
</body>
</html>
2. Create a HTML form that has number of Textboxes. When the form runs in the
Browser fill the textboxes with data. Write JavaScript code that verifies that all
textboxes has been filled. If a textboxes has been left empty, popup an alert
indicating which textbox has been left empty.
if(myArray.length!=0)
{
alert("the following text boxesa are empty:\n"+myArray);
}
}
</script>
</head>
<body bgcolor=cyan>
<h1 align=center> Text Box Validation </h1>
<hr>
<form name="myForm" onSubmit="validate()">
Name : <input type=text name="name" /> <br> <br>
Class :  <input type=text name="class"/> <br> <br>
Age :    <input type=text name="Age"/><br> <br>
<input type="submit" value="Send Message"/>
</form>
</body>
</html>
Html Code:
<!-- Lab3 - Evaluating Arithmetic Expression -->
<html>
<title> Arithmetic expression Evaluation </title>
<script type="text/javascript">
function evaluate()
{
var enteredExpr=document.getElementById("expr").value;
document.getElementById("result").value=eval(enteredExpr);
}
</script>
</head>
<body bgcolor=cyan>
<h1 align=center> Evaluating Arithmetic Expression</h1>
<hr>
<form name="myform">
<b>
   Enter any valid Expression : <input type=text id=expr><br><br>
    <input type=button value="Evaluate" onclick="evaluate()"/><br>
<br>
    Result of the expression : <input type=text id=result><br>
</b>
</form>
</body>
</html>
4. Create a page with dynamic effects. Write the code to include layers and basic
animation.
Html Code:
<html>
<head>
<title> Basic Animation </title>
<style>
#layer1 {position:absolute; top:50px;left:50px;}
#layer2 {position:absolute;top:50px; left:150px;}
#layer3 {position:absolute; top:50px;left:250px;}
</style>
<script type="text/javascript">
function moveImage(layer)
{
var top=window.prompt("Enter Top value");
var left=window.prompt("Enter Left Value");
document.getElementById(layer).style.top=top+'px';
document.getElementById(layer).style.left=left+'px';
}
</script>
<head>
<body bgcolor=cyan>
<div id="layer1"><img src="ball.jpg" onclick="moveImage('layer1')"
alt="MyImage"></div>
<div id="layer2"><img src="ball.jpg" onclick="moveImage('layer2')"
alt="MyImage"></div>
<div id="layer3"><img src="ball.jpg" onclick="moveImage('layer3')"
alt="MyImage"></div>
</body>
</html>
5. Write a JavaScript code to find the sum of N natural Numbers. (Use user-defined
function)
Html Code:
<!-- Lab 5 - Javascript to find the sum of N Natural numbers -->
<html>
<head>
<title> Sum of Natural Numbers </title>
<script type="text/javascript">
function sum()
{
var num=window.prompt("Enter the value of N");
var n =parseInt(num);
var sum=(n*(n+1))/2;
window.alert("Sum of First" + n + "Natural numbers is:"+sum);
}
</script>
</head>
<body bgcolor=cyan>
<h1 align=center> Finding Sum of N Natural Numbers </h1>
<hr>
<form align=center>
<input type="button" value="Click Here " onclick="sum()"/>
</form>
</body>
</html>
6. Write a JavaScript code block using arrays and generate the current date in words,
this should include the day, month and year.
Html Code:
<!-- Lab 6 : Java Script code to display date in words -->
<html>
<head>
<script type="text/javascript">
function display()
{
var dateObj=new Date();
var currDate=dateObj.getDate();
var month=dateObj.getMonth();
var currYear=dateObj.getFullYear();
var year="Two Thousand and Fourteen";
var
days=["First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eigth","Ninth",
"Tenth","Eleventh","Twelfth","Thirteenth","Fourteenth","fifteenth","Sixteenth",
"Seventeenth","Eighteenth","Nineteenth","Twentyeth","Twenty First","Twenty
Second",
"Twenty Third","Twenty Fourth","Twenty Fifth","Twenty Sixth","Twenty
Seventh",
"Twenty Nine","Thirtyeth", "Thirty First"];
var months=["January","Febraury", "March", "April", “May”, “June”, “july”,
“August”, "September","October","November","December"];
if(currYear==2014)
alert("Today date is :: "+days[currDate-1]+" "+months[month-1]+" "+year);
else
alert("Today date is :: "+days[currDate-1]+" "+months[month-1]+" "+currYear);
}
</script>
</head>
<body bgcolor=cyan>
<form>
<input type=button value="Click Here" onClick="display()"/>
</form>
</body>
</html>
7. Create a form for Student information. Write JavaScript code to find Total,
Average, Result and Grade.
Html Code:
<html>
<head>
<title> Student Marks Report </title>
<script type="text/javascript">
function showResult()
{
var name = document.getElementById("name").value;
var cls=document.getElementById("class").value;
var marks1=parseInt(document.getElementById("Sub1").value);
var marks2=parseInt(document.getElementById("Sub2").value);
var marks3=parseInt(document.getElementById("Sub3").value);
var total=marks1+marks2+marks3;
var avg=total/3;
var grade,result;
if(avg>=60)
{
grade="A";
result="First Class";
}
else if(avg<60 && avg>=50)
{
grade="B";
result="Second Class";
}
else if(avg<50 && avg>=40)
{
grade="C";
result="Third Class";
}
else
{
grade="D";
result="Fail";
document.write("<body bgcolor=pink>");
document.write("<h2> Student Marks Report </h2>");
document.write("<hr>");
document.write("<b> Name :"+name+"</b> <br><br>");
document.write("<b> Class :"+cls+"</b> <br><br>");
document.write("<b> Total Marks :"+total+"</b> <br><br>");
document.write("<b> Average :"+avg+"</b> <br><br>");
document.write("<b> Grade :"+grade+"</b> <br><br>");
document.write("<b> Result :"+result+"</b> <br><br>");
document.write("</body>");
}
</script>
</head>
<body bgcolor=cyan>
<form>
<table border="5">
<tr> <th> Student Data Form </th> </tr>
<tr>
<td> Student Name </td>
<td><input type=text id=name></td>
</tr>
<tr>
<td> Class </td>
<td><input type=text id=class></td>
</tr>
<tr>
<td> Subject1 Marks </td>
<td><input type=text id=sub1></td>
</tr>
<tr>
<td> Subject2 Marks </td>
<td><input type=text id=sub2></td>
</tr>
<tr>
<td> Subject3 Marks </td>
<td><input type=text id=sub3></td>
</tr>
</table> <br> <br>
Html Code:
<!-- Lab 8 : Employee Salary Report -->
<html>
<head>
<title> Employee Salary Report </title>
<script type="text/javascript">
function showSalary()
{
var name=document.getElementById("empname").value;
var empno=document.getElementById("empno").value;
var basic = parseInt(document.getElementById("basic").value);
// da is 60% of basic
var da=basic*0.6
gross=basic+hra+da;
// pf is 13% of gross
var pf=gross*0.13;
var deductions=pf+tax;
var netsalary=gross-deductions;
document.write("<body bgcolor=pink>");
document.writeln("<table border='5'>");
document.writeln("<tr><th colspan=2> Employee Salary Report </th> </tr>");
document.writeln("<tr><td> Employee Name:</td> <td>"+name+"</td></tr>");
document.writeln("<tr><td> Emp No : </td> <td>"+empno+"</td></tr>");
document.writeln("<tr><td> Basic Salary :</td> <td>"+basic+"</td></tr>");
document.writeln("<tr><td> HRA (40 % of basic) </td>
<td>"+hra+"</td></tr>");
document.writeln("<tr><td> DA (60 % of basic</td> <td>"+da+"</td></tr>");
document.writeln("<tr><td> Gross salary : </td> <td>"+gross+"</td></tr>");
document.writeln("<tr><td> PF ( 13% of the basic )</td>
<td>"+pf+"</td></tr>");
document.writeln("<tr><td> Tax (20% of the gross) : </td>
<td>"+tax+"</td></tr>");
document.writeln("<tr><td>Deductions (PF + Tax) </td>
<td>"+deductions+"</td></tr>");
document.writeln("<tr><td>Net Salary (Gross - Deductions) : </td>
<td>"+netsalary+"</td></tr>");
document.writeln("</table>");
document.write("</body>");
</script>
<body bgcolor="cyan")
<form>
<table border="5">
<tr> <th colspan=2> Employee Salary Form </th></tr>
<tr>
<td> Employee Name :</td>
<td> <input type="text" id="empname"/></td>
</tr>
<tr>
<td> Employee Number </td>
<td> <Input Type ="text" id="empno"/> </td>
</tr>
<tr>
<td> Basic Pay </td>
<td> <input type=text id=basic /></td>
</tr>
</table>
<br>
<input type=button value="Show Salary" onclick="showSalary()">
</form>
</html>
9. Create a form consists of a two Multiple choice lists and one single choice list,
The first multiple choice list, displays the Major dishes available.
The second multiple choice list, displays the Starters available.
The single choice list, displays the Soft drinks available.
The selected items from all the lists should be captured and displayed in a Text Area
along with their respective costs. On clicking the ‘Total Cost’ button, the total cost of
all the selected items is calculated and displayed at the end in the Text Area. A
‘Clear’ button is provided to clear the Text Area.
Html Code:
<html>
<head>
<title> MacDonalds Restaurant </title>
<script text="text/javascript">
function findCost()
{
var major=document.getElementById("major");
var starters = document.getElementById("starters");
var soft = document.getElementById("soft");
var selectedItems="Item\t\t\t Price \n..................\n";
var totcost=0;
}
}
}
}
var softdrinkIndex=soft.selectedIndex;
if(softdrinkIndex!=-1)
{
var selectedSoftdrink=soft.options[soft.selectedIndex].text;
var price = parseInt(soft.options[soft.selectedIndex].value);
totcost=totcost+price;
selectedItems=selectedItems+selectedSoftdrink+"\t\t\t"+price+"\n.....................\n";
<tr>
<td> Major Dishes : </td>
<td> <select id=major size=3 multiple="multiple">
<option value=100> Vegetable Pulav </option>
<option value=150> Hyderabadi Biriyani </option>
<option value=50> Roti with Curry </option>
</td>
</tr>
<tr>
<td> Starters </td>
<td> <select id="starters" size=3 multiple="multiple">
<option value=80> Gobi Manchurian </option>
<option value=40> Veg Soup </option>
<option value=30> Masala Papad </option>
</td>
</tr>
<tr>
<td> Soft Drinks </td>
<td> <select id="soft" size=1>
<option value=20> Pepsi </option>
<option value=30> Coke </option>
<option value=10>LimeSoda</option>
</select>
</td>
</tr>
<tr>
<td colspan=2 align=center>
<textarea id="ordereditems" rows=10 cols=40>
</textarea>
</td>
</tr>
<tr>
<td> <input type=button value="Find Total Cost"
onClick="findCost()"/></td>
<td> <input type=reset value=clear /></td>
</tr>
</table>
</form>
</html>
10. Create a web page using two image files, which switch between one another as
the mouse pointer moves over the images. Use the onMouseOver and
onMouseOut event handlers.
Html Code:
<!-- Lab 10 Image files , Switch between one another as the mouse pointer moves over
the images -->
<html>
<head>
<title> Mouse Over and Mouse Out </title>
<style type="text/css">
#image1{position:absolute; top:50px, left:50px , border:thin, visibility:visible;}
#image2{position:absolute; top:50px, left:50px , border:thin, visibility:hidden;}
</style>
<script type="text/javascript">
function changeImage()
{
var imageOne=document.getElementById("image1").style;
var imageTwo=document.getElementById("image2").style;
if(imageOne.visibility=="visible")
{
imageOne.visibility="hidden";
imageTwo.visibility="visible";
}
else
{
imageOne.visibility="visible";
imageTwo.visibility="hidden";
}
}
</script>
</head>
<body bgcolor="cyan" text=blue>
<h1 align = center> Mouse Events </h1>
<hr>
<form >
<img src="zoozoo1.jpg" id="image1" onMouseOver="changeImage()"
onMouseOut="changeImage()"></img>
<img src="zoozoo2.jpg" id="image2" onMouseOver="changeImage()"
onMouseOut="changeImage()"></img>
</form>
</body>
</html>
Figure 2--Mouse In
PART-B
1. Write a HTML program to demonstrate Ordered, Unordered and Definition
List
<html>
<head>
<title> Lists</title></head>
<body>
<p><b> Unordered List </b></p>
<ul type="square">
<li>PMCS</li>
<li>BCAS</li>
<li>MCA</li>
<li>MSC</li>
</ul>
<p><b> Ordered List </b></p>
<ol type="a">
<li>PMCS</li>
<li>BCA</li>
<1i>MCA</li>
<li>MSC</li></ol>
<p><b> Definition List </b></p>
<dl>
<dt><b>PMCS</b></dt>
<dd>This stands for Physics, Mathematics and Computer Science</dd>
<dt><b>BCA</b></dt>
<dd>This stands for Bachelor of Computer Applications </dd>
</dt>
</body>
</html>
3. Write a Java Script program to perform arithmetic operation using user Input.
<html>
<head>
<title>Arithmetic Operations </title>
<script type="text/javascript">
var a,b,c,ch;
a=parseInt(prompt("Enter First Number"));
b=parseInt(prompt("Enter Second Number"));
ch=parseInt(prompt("Enter your choice...."));
switch(ch)
{
case 1:
c=a+b;
document. write("Addition="+c);
break;
case 2:
c=a-b;
document.write("Subtraction="+c);
break;
case 3:
c=a*b;
document.write("Multiplication="+c);
break;
case 4:
c=a/b;
document.write("Division="+c);
break;
default:
document.write("Invalid choice");
}
</script>
</head>
</html>
4. Write a Java Script program to find factorial of a given number using user
defined function.
<html>
<head>
<title> Factorial </title>
<script type="text/javascript">
function factorial()
{
var n,i,f=1;
n=parseInt(prompt("Enter Number"));
for(i=1;i<=n;i++)
{
f=f*i;
}
document.write("Factorial="+f);
}
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type="button" onclick="factorial()" value="Factorial">
</form>
</body>
</html>
partb7.js
var dom;
function move(movee, newTop, newLeft)
{
dom = document.getElementById(movee).style;
dom.top=newTop + "px";
dom.left=newLeft + "px";
}
8. Write a program using CSS to display image on your choice and write few line
about it.
<html>
<head>
<style type="text/css">
p.indent {text-indent:0.5in}
img {float:right}
</style>
<body>
<img src="pp.jpg" width=600 height=600 alt="AboutVidhanaSoudha"/>
<p class="indent">One of the most famous landmarks of Bangalore,the Vidhana
Soudha houses the State Legislature and the Secretariatof Karnataka.The origin
of the building dates back to the times of Sri KengalHanumanthaiah, the Chief
Ministerof Mysorefrom1951to 1956.</p>
<p class="indent">Thefoundation of the building was laid by the PM, Sri Pandit
Jawaharlal Nehru on 13th July, 1951.It was completed in the year 1956andthe
total cost came around Rs. 1.75 crore.</p>
</body>
</html>
9. Write a Java Script program to display browser name and version using
navigator object.
partb9.html
<html>
<head>
<title>Navigator</title>
<script type="text/javascript" src="partb9.js">
</script>
</head>
<body onload="navproperties();">
</body>
</html>
partb9.js
function navproperties()
{
alert("Browser is :" + navigator.appName + "\n" + "The version number is :" +
navigator.appVersion + "\n");
}