LAB PROGRAM
LAB PROGRAM
<!DOCTYPE html>
<html>
<script type="text/javascript">
function countFormElements()
</script></head><body bgcolor=cyan>
<hr />
</form>
</body>
</html>
1.OUTPUT:
<head>
<title> Validate Text Boxes </title>
<script type="text/javascript">
function validate()
{
var myArray=new Array();
for(var i=0;i<document.myForm.length;i++)
{
if(document.myForm.elements[i].value.length==0)
{
myArray.push(document.myForm.elements[i].name);
}
}
if(myArray.length!=0)
{
alert("the following text boxesa are empty:\n"+myArray);
}
}
</script>
</head>
<body bgcolor="yellow">
<html>
function evaluate()
var enteredExpr=document.getElementById("expr").value;
document.getElementById("result").value=eval(enteredExpr);
</script>
</head><body bgcolor=cyan>
<form name="myform">
<b>
Enter any valid Expression : <input type=text id=expr><br /><br />
<br />
</b>
</form>
</body>
</html>
3.OUTPUT:
4. BASIC ANIMATION:
<html>
<head>
<style>
</style>
<script type="text/javascript">
function moveImage(layer)
document.getElementById(layer).style.left=left+'px';
</script>
<head>
<body bgcolor=cyan>
<div id="layer1">
</div>
</div>
</div>
</body>
</html>
OUTPUT:
5.FINDING SUM OF N NUMBERS:
<html>
<head>
<script type="text/javascript">
function sum()
var n =parseInt(num);
var sum=(n*(n+1))/2;
</script>
<hr />
<form align=left>
</form>
</body>
</html>
OUTPUT:
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:
<html>
<head>
<title>Display Date </title>
<script type="text/javascript">
function display()
var currDate=dateObj.getDate();
var month=dateObj.getMonth();
var currYear=dateObj.getFullYear();
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"];
if(currYear==2014)
7. Create a form for Student information. Write JavaScript code to find Total, Average, Result and Grade.
Html Code:
<html>
<head>
document.write("<body bgcolor="red">");
</body></html>
8. Create a form for Employee information. Write JavaScript code to find DA, HRA, PF, TAX, Gross pay,
Deduction and Net pay.
<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); // hra is 40% of basic var
hra=basic*0.4; // da is 60% of basic var da=basic*0.6 gross=basic+hra+da; // pf is
13% of gross var pf=gross*0.13; // tax is 20%of gross var tax=0.2*gross;
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.
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 theselected items is calculated
and displayed at the end in the Text Area. A ‘Clear’ button is provided to clear the Text Area.
Html Code:
<tr> <th colspan=2 align=center> <h2> Items Menu</h2> </th> </tr> <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>
Example:
Html Code:
<!-- Lab 6 : Finding factorial of a given number N --><html> <head> <title> Factorail of a Number
</title> <script type="text/javascript"> function findFactorial() { var
num=window.prompt("Enter the value of N : "); var n=parseInt(num);
window.alert("Factorial of "+n+" is "+fact(n)); } function fact(n) { if(n==0)
return 1; else return (n*fact(n-1)); }
</script> </head> <body bgcolor=cyan> <h1 align=center> Factorial of a Number </h1> <hr>
<center> <form> <input type=button value=ClickHere onclick="findFactorial()"/> </form>
</center> </body></html>