Ss-Web Mannual
Ss-Web Mannual
Ss-Web Mannual
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.
<html>
<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>
3. Develop a HTML Form, which accepts any Mathematical expression. Write
JavaScript code to Evaluates the expression and Displays the result.
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>
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>
7. 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 7 : 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"];
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>
8. Create a form for Student information. Write JavaScript code to find Total, Average,
Result and Grade.
Html Code:
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
<script type = "text/javascript">
function calc()
{
var m1,m2,m3,avg = 0,total = 0, result = "",grade = "";
m1 = parseInt(document.form1.wp.value);
m2 = parseInt(document.form1.sp.value);
m3 = parseInt(document.form1.cg.value);
total = m1+m2+m3;
avg = total/3;
if( m1 < 35 || m2 < 35 || m3 < 35)
{
result = "fail";
grade = "D";
}
else if(avg >= 75)
{
result = "Distinction";
grade = "A+";
}
else if(avg >= 60 && avg < 75)
{
result = "First class";
grade = "A";
}
else if(avg >= 50 && avg < 60)
{
result = "Second class";
grade = "B";
}
else if(avg >=35 && avg < 50)
{
result = "Pass class";
grade = "C";
}
else if (avg < 35)
{
result = "Fail";
Grade = "D";
}
document.form1.result.value = result;
document.form1.grade.value = grade;
document.form1.total.value = total;
document.form1.average.value = avg;
}
</script>
</head>
<body bgcolor="cyan">
<form name = "form1">
<table border = "1">
<tr>
<td> Student Name</td>
<td><input type = "text" /></td>
</tr>
<tr>
<td colspan = "2" align = "center">Subject Marks</td>
</tr>
<tr>
<td>Web Programming</td>
<td><input type = "text" name = "wp" /></td>
</tr>
<tr>
<td>TOC</td>
<td><input type = "text" name = "cg" /></td>
</tr>
<tr>
<td>System Programming</td>
<td><input type = "text" name = "sp" /></td>
</tr>
<tr>
<td colspan = "2" align = "center"><input type = "button" onclick = "calc()"
value = "calculte" /></td>
</tr>
<tr>
<td>Total</td>
<td><input type = "text" name = "total"/></td>
</tr>
<tr>
<td>Average</td>
<td><input type = "text" name = "average" /></td>
</tr>
<tr>
<td>Result</td>
<td><input type = "text" name = "result" /></td>
</tr>
<tr>
<td>Grade</td>
<td><input type = "text" name = "grade"/></td>
</tr>
</table>
</form>
</body>
</html>
9. Create a form for Employee information. Write JavaScript code to find DA, HRA, PF,
TAX, Gross pay, Deduction and Net pay.
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);
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>
10. 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;
for(var i=0;i<major.options.length; i++)
{
var option = major.options[i];
if(option.selected==true)
{
var price = parseInt(option.value);
totcost=totcost + price;
selectedItems=selectedItems+option.text+"\t\t"+price+"\n";
}
}
}
}
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";
</script>
</head>
<body bgcolor=cyan text=blue>
<h1 align=center> Mc Donald's Restaurant </h1>
<hr>
<form name="Menu Form">
<table border=10 align=center>
<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>
11. Write a JavaScript code block, which checks the contents entered in a form’s Text
element. If the text entered is in the lower case, convert to upper case. Make use of
function to Uppercase ( ).
Html Code:
<!-- Lab 11 Changing lower case to Upper case and vice versa -->
<html>
<head>
<title> Case Conversion </title>
<script type="text/javascript">
function toUpper()
{
document.getElementById("name").value=document.getElementById("name").value.toUpperCa
se();
function toLower()
{
document.getElementById("name").value=document.getElementById("name").value.toLowerCa
se();
}
</script>
</head>
<body bgcolor="cyan">
<form>
Enter your Name : <input type=text id=name size=50/>
<input type=button value="Convert to Upper" onClick="toUpper()"/>
<input type=button value="Convert to Lower" onClick="toLower()"/>
</form>
</body>
</html>
12. 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 12 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>
*******
1. Write a HTML Program to display list of fruits, vegetables and cereals using
ordered list.
<html>
<head>
<title>Ordered list</title>
</head>
<body bgcolor="red">
<h4>list of fruits</h4>
<li>Strawberry</li>
<li>Fig</li>
<li>Mango></li>
<li>Pineapple></li>
</ol>
<h4>list of vegetables</h4>
<li>tomato</li>
<li>cauliflower</li>
<li>carrot</li>
<li>beans<li>
</ol>
<h4>list of cereals</h4>
<li>rice</li>
<li>jowar</li>
<li>groundnuts</li>
<ol>
</body>
</html>
<li>rice</li>
<li>jowar</li>
<li>groundnuts</li>
<ol>
</body>
</html>
2. Write a HTML Program to display list of fruits, vegetables and cereals using
Unordered list.
<html>
<head>
<title>unOrdered list</title>
</head>
<body bgcolor="pink">
<h4>list of fruits</h4>
<ul type="disc">
<li>Strawberry</li>
<li>Fig</li>
<li>Mango</li>
<li>Pineapple</li>
</ul>
<h4>list of vegetables</h4>
<ul type ="square">
<li>tomato</li>
<li>cauliflower</li>
<li>carrot</li>
<li>beans<li>
</ul>
<h4>list of cereals</h4>
<ul type="circle">
<li>rice</li>
<li>jowar</li>
<li>groundnuts</li>
<ul>
</body>
</html>
<tr bgcolor="powderblue">
<td align="center">Days/Time
<td>8:45-9:45
<td>9:45-10:00
<td>10:00-11:00
<td>11:00-12:00
<td rows="6">12:00-12:45
<td>12:45-1:45
<td>1:45-2:45
<td>2:45-3:45
</tr>
<tr bgcolor="#00ffbf">
<td align="center" bgcolor="#00ff40">MONDAY
<td align="center">TOC
<td align="center" rowspan="6">B<br>R<br>E<br>A<br>K<br>
<td align="center">WP<br>
<td align="center">SP<br>
<td rowspan="6" align="center" bgcolor="powder">L<br>U<br>N<br>C<br>H<br>
<td align="center">CNS<br>
<td align="center">PROJECT<br>
<td align="center">CAIT<br>
</tr>
<tr bgcolor="#00ffbf">
<td align="center" bgcolor="#00ff40">TUESDAY
<td align="center">CNS
<td align="center">TOC<br>
<td align="center">WP<br>
<td align="center">SP<br>
<td align="center">CAIT<br>
<td align="center">WP LAB<br>
</tr>
<tr bgcolor="#00ffbf">
<td align="center" bgcolor="#00ff40">WEDNESDAY
<td align="center">WP
<td align="center">TOC<br>
<td align="center">SP<br>
<td align="center">CNS<br>
<td align="center">CAIT<br>
<td align="center">PROJECT<br>
</tr>
<tr bgcolor="#00ffbf">
<td align="center" bgcolor="#00ff40">THURSDAY
<td align="center">CNS
<td align="center">TOC<br>
<td align="center">WP<br>
<td align="center">SP<br>
<td align="center">CAIT<br>
<td align="center">WP LAB<br>
</tr>
<tr bgcolor="#00ffbf">
<td align="center" bgcolor="#00ff40">FRIDAY
<<td align="center">WP
<td align="center">TOC<br>
<td align="center">SP<br>
<td align="center">CNS<br>
<td align="center">CAIT<br>
<td align="center">PROJECT<br>
</tr>
<tr bgcolor="#00ffbf">
<td align="center" bgcolor="#00ff40">SATURDAY
<td align="center">WP
<td align="center" colspan="2">PROJECT<br>
</tr>
</body>
</html>
3. Write a HTML Program to demonstrate Form and Form Controls.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<label for="male">Male</label>
<label for="female">Female</label><br><br><br>
<b>Areas of interest</b>:
<b>
uploadfile</b>: <input type="file"><br><br><br>
<input type="submit" value="Register">
</form>
</body>
</html>
</style>
</head>
<body>
</body>
</html>
5. Write a HTML Program to demonstrate Confirm Box.
<html>
<head>
<script type ="text/javascript">
function show_confirm()
{
var r =confirm ("Press a button");
if(r==true)
{
alert("We pressed OK!");
}
else
{
alert("We Pressed Cancel!")
}
}
</script>
</head>
</body>
<input type="button"onclick="show_confirm()"value="Show confirm box"/>
</body>
</html>
</script>
</head>
<body>
<input type="button"onclick="show_prompt()"value="Show prompt box"/>
</body>
</html>
{
var3 = var1 + var2;
var1 = var2;
var2 = var3;
document.write(var3+"<br />");
}
</script>
</body>
</html>
<html>
<head>
<script>
function palin()
{
var a,no,b,temp=0;
no=Number(document.getElementById("no_input").value);
b=no;
while(no>0)
{
a=no%10;
no=parseInt(no/10);
temp=temp*10+a;
}
alert(temp);
}
</script>
</head>
<body>
Enter any Number: <input id="no_input">
<button onclick="palin()">Check</button></br></br>
</body>
</html>