Web Lab Manual2021
Web Lab Manual2021
Web Lab Manual2021
PART -A
1. Create a form having number of elements (Textboxes, Radio buttons, Checkboxes,
and so on). Write JavaScript code to count the number of elements in a form.
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.
3. Develop a HTML Form, which accepts any Mathematical expression. Write JavaScript
code to Evaluates the expression and Displays the result.
4. Create a page with dynamic effects. Write the code to include layers and basic animation.
5. Write a JavaScript code to find the sum of N natural Numbers. (Use user-defined function)
6. Write a JavaScript code block using arrays and generate the current date in words, this
should include the day, month and year.
7. Create a form for Student information. Write JavaScript code to find Total, Average,
Result and Grade.
8. Create a form for Employee information. Write JavaScript code to find DA, HRA, PF,
TAX, Gross pay, Deduction and Net pay.
9. Create a form consists of a two Multiple choice lists and one single choice list
(a) The first multiple choice list, displays the Major dishes available
(b) The second multiple choice list, displays the Starters available.
(c)The single choice list, displays the Soft drinks available.
10. Create a web page using two image files, which switch between one another as the mouse
pointer moves over the image. Use the on Mouse Over and on Mouse Out event handlers.
PART – B
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.
emptytextboxes=emptytextboxes+document.textboxForm.elements[i].name+"\n";
count++;
}
}
if(count==0)
window.alert("All textboxes are filled");
else if(count==textboxcount-1)
window.alert("No textboxes are filled");
else
window.alert(emptytextboxes);
}
3. Develop a HTML Form, which accepts any Mathematical expression. Write JavaScript
code to Evaluates the expression and Displays the result.
prg3.html
<html>
<head>
<title>Mathematical Expression</title>
<script type="text/javascript" src="prg3.js"></script>
</head>
<body>
<center>
<h2>Arithmetic Operations</h2>
<hr/>
<br/>
<form name="mathForm">
<table border="1" cellpadding="5" cellspacing="5">
<tr>
<th>Enter the First Operand</th>
<th>Select the Operation</th>
<th>Enter the Second Operand</th>
<th>Result</th>
</tr>
<tr>
<td><input type="text" name="op1"/></td>
<td>
<select name="operator">
<option name="sum" value="+">+</option>
<option name="diff" value="-">-</option>
<option name="prod" value="*">*</option>
<option name="div" value="/">/</option>
<option name="mod" value="%">%</option>
<option name="exp" value="exp">exp</option>
</select>
</td>
<td><input type="text" name="op2" /></td>
<td><input type="text" name="result" readonly="readonly"/></td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="button" name="calresult" value="Calculate" onclick="calculate()">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
prg3.js
function calculate()
{
var validinput=/[0-9,.,-]/
var op1=document.mathForm.op1.value;
var op2=document.mathForm.op2.value;
var operator=document.mathForm.operator.value;
var result=0;
if(op1.length==0)
window.alert("Please enter the first element");
else if(op2.length==0)
window.alert("Please enter the second element");
else if(op1.search(validinput)==-1)
window.alert("Operand1 is not a numeric value");
else if(op2.search(validinput)==-1)
window.alert("Operand2 is not a numeric value");
else
{
var n1=parseFloat(op1);
var n2=parseFloat(op2);
switch(operator)
{
case "+":result=n1+n2;break;
case "-":result=n1-n2;break;
case "*":result=n1*n2;break;
case "/":result=n1/n2;break;
case "%":result=n1%n2;break;
case "exp":result=Math.pow(n1,n2);break;
}
document.mathForm.result.value=result;
}
}
OUTPUT
4. Create a page with dynamic effects. Write the code to include layers and basic animation.
prg4.html
<html>
<head>
<title>Basic Animation</title>
<script type="text/javascript" src="prg4.js"></script>
<style type="text/css">
#layer1
{background-color:red;
position:absolute;
height:200px;
width:200px;
left:50px;
top:200px;
}
#layer2
{background-color:yellow;
position:absolute;
height:150px;
width:150px;
left:75px;
top:225px;
}
#layer3
{background-color:blue;
position:absolute;
height:100px;
width:100px;
left:100px;
top:250px;
}
</style>
</head>
<body>
<h2>Basic Animation</h2>
<hr><br/>
<p id="layer1">Layer1 is red color</p>
<p id="layer2">Layer2 is yellow color</p>
<p id="layer3">Layer3 is blue color</p>
<form name="animationForm">
<input type="button" name="ani1" value="Move Red Towards Right"
onclick="moveRed()"/>
<input type="button" name="ani2" value="Move Yellow Towards Right"
onclick="moveYellow()"/>
<input type="button" name="ani3" value="Move Blue Towards Right"
onclick="moveBlue()"/><br/>
<input type="button" name="ani4" value="Show yellow Layer"
onclick="showYellow(true)"/>
<input type="button" name="ani5" value="Hide yellow Layer"
onclick="showYellow(false)"/>
</form>
</body>
</html>
prg4.js
function moveRed()
{
document.getElementById("layer1").style.left="70px";
}
function moveYellow()
{
document.getElementById("layer2").style.left="95px";
}
function moveBlue()
{
document.getElementById("layer3").style.left="120px";
}
function showYellow(status)
{
if(status)
document.getElementById("layer2").style.visibility="visible";
else
document.getElementById("layer2").style.visibility="hidden";
}
5. Write a JavaScript code to find the sum of N natural Numbers. (Use user-defined function)
prg5.html
<html>
<head>
<title> Sum of n natural numbers</title>
<script type="text/javascript" src="prg5.js"></script>
</head>
<body>
<h2>Sum of Natural numbers</h2>
<hr/>
<p>please click the button to calculate sum of n natural numbers</p>
<input type="button" name="calsum" value="Calculate sum of n natural numbers"
onclick="calculate()"/>
</body>
</html>
prg5.js
function calculate()
{
var number=window.prompt("enter the number",0);
var no=parseInt(number);
var sum=(no*(no+1))/2;
window.alert("sum of first"+number+"natural numbers is "+sum);
}
OUTPUT
6. Write a JavaScript code block using arrays and generate the current date in words, this
should include the day, month and year.
prg6.html
<html>
<head>
<title>Date Display</title>
7. Create a form for Student information. Write JavaScript code to find Total, Average,
Result and Grade.
prg7.html
<html>
<head>
<title>Student Details</title>
<script type="text/javascript"src="prg7.js"></script>
</head>
<body>
<center>
<h2>Student details</h2> <hr/> <br/>
<h4>please fill in the following student details</h4>
<br/>
<form name="student">
<table cellpadding="5" cellspacing="5">
<tr> <td>Student Name:</td>
<td><input type="text"name="name"/></td> </tr>
<tr> <td>Register No:</td>
<td><input type="text"name="regno"/></td> </tr>
<tr> <td>Theory of computation:</td>
<td><input type="text"name="toc"/></td> </tr>
<tr> <td>System Programming:</td>
<td><input type="text"name="sp"/></td> </tr>
<tr> <td>Cryptography and network security:</td>
<td><input type="text"name="cns"/></td> </tr>
<tr> <td>Web Programming:</td>
<td><input type="text"name="wp"/></td> </tr>
</table> <br/> <br/>
<input type="button"name="result"value="view Result"onclick="calculate()"/>
</form>
</center>
</body>
</html>
prg7.js
function calculate()
{
var name=document.student.name.value;
var regno=document.student.regno.value;
var m1=parseInt(document.student.toc.value);
var m2=parseInt(document.student.cns.value);
var m3=parseInt(document.student.sp.value);
var m4=parseInt(document.student.wp.value);
var total=m1 + m2 + m3 + m4;
var avg=total/4;
var grade,result;
if(m1<40 || m2<40 || m3<40 || m4<40)
{
grade="D";
result="Fail";
}
else
{
if(avg>=60)
{
grade="A";
result="First Class";
}
else if(avg>=50)
{
grade="B";
result="Second Class";
}
else if(avg>=40)
{
grade="C";
result="Pass";
}
else
{
grade="D";
result="Fail";
}
}
document.writeln("<h2>Student Results</h2>");
document.writeln("<pre><b>Name:" + name + "</b></pre>");
document.writeln("<pre><b>Register No:" + regno + "</b></pre>");
document.writeln("<pre><b>Total Marks:" + total + "</b></pre>");
document.writeln("<pre><b>Average:" + avg + "</b></pre>");
document.writeln("<pre><b>Grade:" + grade + "</b></pre>");
document.writeln("<pre><b>Result:" + result + "</b></pre>");
}
8. Create a form for Employee information. Write JavaScript code to find DA, HRA, PF,
TAX, Gross pay, Deduction and Net pay.
Prg8.html
<html>
<head>
<title>Employee Details</title>
<script type="text/javascript" src="prg8.js"></script>
</head>
<body>
<center>
<h2>Employee Details</h2>
<hr><br/>
<h4>Please fill in the following EMPLOYEE details</h4><br/>
<form name="employee">
<table cellpadding="5" cellspacing="5">
<tr><td>Employee Name:</td>
<td><input type="text" name="name"/></td></tr>
<tr><td>Employee No:</td>
<td><input type="text" name="empno"/></td></tr>
<tr><td>Basic Pay:</td>
<td><input type="text" name="basicpay"/></td></tr>
</table><br/><br/>
<input type="button" name="details" value="View Salary Details" onclick="calculate()"/>
</form>
</center>
</body>
</html>
Prg8.js
function calculate()
{
var name=document.employee.name.value;
var empno=document.employee.empno.value;
var bp=parseInt(document.employee.basicpay.value);
var hra=0.4*bp;
var da=0.6*bp;
var gross=bp + hra + da;
var pf=0.13*gross;
var tax=0.2*gross;
var deductions=pf + tax;
var netsalary=gross - deductions;
document.writeln("<h2>Employee Salary Details</h2>");
document.writeln("<pre><b>Name:" + name + "</b></pre>");
document.writeln("<pre><b>Employee No:" + empno + "</b></pre>");
document.writeln("<pre><b>Basic Salary:Rs." + bp + "</b></pre>");
document.writeln("<pre><b>HRA(40% of Basic):Rs." + hra + "</b></pre>");
document.writeln("<pre><b>DA(60% of Basic):Rs." + da + "</b></pre>");
document.writeln("<pre><b>Gross Salary:Rs." + gross + "</b></pre>");
document.writeln("<pre><b>PF(13% of Gross):Rs." + pf + "</b></pre>");
document.writeln("<pre><b>TAX(20% of Gross):Rs." + tax + "</b></pre>");
document.writeln("<pre><b>Deductions:Rs." + deductions + "</b></pre>");
document.writeln("<pre><b>Net Salary:Rs." + netsalary + "</b></pre>");
}
OUTPUT
9. Create a form consists of a two Multiple choice lists and one single choice list
(a) The first multiple choice list, displays the Major dishes available
(b) The second multiple choice list, displays the Starters available.
(c)The single choice list, displays the Soft drinks available.
Prg9.html
<html>
<head>
<title>Resturant menu details</title>
Prg9.js
var totalprice=0;
function display()
{
totalprice=0;
var selectedItems="Items\t\t\tPrice\n---------------------------------------\n";
var index1=document.resturant.major.length;
var index2=document.resturant.starters.length;
var index3=document.resturant.softdrinks.length;
for(var i=0;i<index1;i++)
{
if(document.resturant.major.options[i].selected)
{
var item=document.resturant.major.options[i].text;
var value=document.resturant.major.options[i].value;
totalprice=totalprice+parseInt(value);
selectedItems=selectedItems+item+"\t\t"+value+"\n";
}
}
for(var i=0;i<index2;i++)
{
if(document.resturant.starters.options[i].selected)
{
var item=document.resturant.starters.options[i].text;
var value=document.resturant.starters.options[i].value;
totalprice=totalprice+parseInt(value);
selectedItems=selectedItems+item+"\t\t"+value+"\n";
}
}
for(var i=0;i<index3;i++)
{
if(document.resturant.softdrinks.options[i].selected)
{
var item=document.resturant.softdrinks.options[i].text;
var value=document.resturant.softdrinks.options[i].value;
totalprice=totalprice+parseInt(value);
selectedItems=selectedItems+item+"\t\t"+value+"\n";
}
}
document.resturant.ordereditems.value=selectedItems;
}
function calculate()
{
display();
document.resturant.ordereditems.value=document.resturant.ordereditems.value+"\nTotal
Price:Rs."+totalprice;
}
Output
10. Create a web page using two image files, which switch between one another as the mouse
pointer moves over the image. Use the on Mouse Over and on Mouse Out event handlers.
Prg10.html
<html>
<head>
<title>Mouse Over and Mouse Out</title>
<script type="text/javascript" src="prg10.js"></script>
<style type="text/css">
#image1
{position:absolute;
visibility:visible;
width:300px;
height:200px;
left:500px;}
#image2
{position:absolute;
visibility:hidden;
width:300px;
height:200px;
left:500px;}
</style></head>
<body><center>
<h2>Mouse Over and Mouse Out</h2><hr/><br/><br/>
<img src="image1.jpg" id="image1" onmouseover="changeImage()"
onmouseout="changeImage()"/>
<img src="image2.jpg" id="image2" onmouseover="changeImage()"
onmouseout="changeImage()"/>
</center>
</body>
</html>
Prg10.js
function changeImage()
{
var img1=document.getElementById("image1").style;
var img2=document.getElementById("image2").style;
if(img1.visibility=="visible")
{
img1.visibility="hidden";
img2.visibility="visible";
}
else
{
img1.visibility="visible";
img2.visibility="hidden";
}
}
PART B
1. Create a web page to display different types of lists
<html>
<head>
<title>subjects</title>
</head>
<body>
<ul >
<h3>FIRST SEMESTER</h3>
<li>C</li>
<li>DS</li>
<li>DM</li>
</ul>
<ul type = “square”>
FIRST SEMESTER
<li>C</li>
<li>DE</li>
<li>DM</li>
</ul>
<ul type = “circle”>
SECOND SEMESTER
<li>DS</li>
<li>DBMS</li>
<li>NM</li>
</ul>
<ul type = “disc”">
THIRD SEMESTER
<li>C++</li>
<li>OS</li>
<li>AFM</li>
</ul>
<ol type="A">
FOURTH SEMESTER
<li>VP</li>
<li>UNIX</li>
<li>OS</li>
</ol>
<ol type="a">
FIFTH SEMESTER
<li>CA</li>
<li>SE</li>
<li>MP</li>
</ol>
<ol type="1">
SIXTH SEMESTER
<li>SP</li>
<li>TOC</li>
<li>WP</li>
<li>CNS</li>
</ol>
<dl>
<dt> HTML
<dd> HTML is the standard markup language for creating Web pages. </dd>
</dt>
</dt>
</body>
</html>
2. Create a web page to demonstrate table tag.
<html>
<table border="5">
<tr>
<th colspan="2">
<h3><br> Marksheet</h3>
</th>
</tr>
<th>SUBJECTS</th>
<th>MARKS</th>
<tr>
<td>Web programming</td>
<td>70</td>
</tr>
<tr>
<td>Theory of computation</td>
<td>100</td>
</tr>
<tr>
<td>System programming</td>
<td>100</td>
</tr>
<tr>
<td>CNS</td>
<td>100</td>
</tr>
</table>
</html>
<script type="text/javascript">
function factorial()
{
var n=parseInt(document.factorialofn.inputvalue.value);
var fact=1;
if(n<0)
alert("please enter a positive value");
else if(n==0)
alert("Factorial of 0 is:" +1);
else
{
for(i=n;i>=1;i--)
fact=fact*i;
alert("Factorial of "+n+" is "+fact);
}
}
</script>
</head>
<body>
<center>
<h2>Factorial of a number</h2><hr/><br/><br/>
<form name="factorialofn">
<table border="2" cellpading="5" cellspacing="5">
<tr><td><strong>Enter a number:</strong></td>
<td><input type="text" name="inputvalue" value="0"/></td></tr>
<tr><td colspan="2" align="center">
<input type="button" name="factcal" value="Factorial" onclick="factorial()"></td></tr>
</form>
</center>
</body>
</html>
OUTPUT
</head>
<body>
<center>
<h2>Lowercase to Uppercase Conversion</h2>
<hr/>
<br/><br/>
<form name="caseconversion">
<table border="2" cellpadding="5" cellspacing="5">
<tr>
<td><strong>Enter the text :</strong></td>
<td><input type="text" name="content"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" name="convert" value="Click to
convert to uppercase" onclick="conversion()"/></td>
</tr>
</table>
</form>
</center>
</body>
</html>
<html>
<head>
<title>Style></title>
<style type="text/CSS">
a:hover
{
color : yellow;
font-size : 16px;
}
a:visited
{
color : brown;
}
</style>
<head>
<body bgcolor ="#A4F9C3">
<ul>SUBJECTS
<li><a href="sub1.html">SP</a></li>
<li><a href="sub2.html">TOC</a></li>
<li><a href="sub3.html">CNS</a></li>
<li><a href="sub4.html">WP</a></li>
</ul>
</body>
</html>
16. Create a web page using different levels of style sheet.
<!DOCTYPE html>
<html>
<body>
Inline Example:
<p style="color:blue; padding:10px; text-decoration:underline;"> Applies styles directly to
the elements(tags) by using style attribute</p>
Internal Example:
<style>
p{color:red; padding:10px; text-decoration:underline;}
</style>
<p> Applies styles to HTML by Placing The CSS rules inside the style tag</p>
External Example:
<link rel="stylesheet" type="text/css" href="prg11.css">
<h1>Applies styles as a separate file with a .css extension</h1>
</body>
</html>
17. Create a web page to demonstrate different types of selectors
<html>
<head>
<title> sample CSS</title>
<style type="text/css">
#ID2
{
color:red;
}
p.blue
{
color:blue;
}
.BLUE
{
color:green;
}
</style>
</head>
<body>
<p id="ID2"> The #id selector styles the XHTML element with the specified id </p>
<p class="blue"> the class slector is used to allow different occurrances of same tag</p>
<h2 class="BLUE"> A generic class can be defined if you want to apply a style</h2>
<h4 class="BLUE"> A generic class can be defined if you want to apply a style</h4>
</body>
</html>