Simple Java Script Programs
Addition Of Two Values With Variables:
<html>
<script>
var a;
var b;
var c;
a=5;
b=6;
c=a+b
document.write(c)
</script>
</html>
|
Mathematical Operation In An Array:
<html>
<script>
myarr= new Array(8);
myarr[0]=10
myarr[1]=20
myarr[2]=30
myarr[3]=40
myarr[4]=50
myarr[5]=60
myarr[6]=70
myarr[7]=80
a=myarr[0]*myarr[4]
b=myarr[1]+myarr[5]
c=myarr[6]-myarr[2]
d=myarr[3]/myarr[7]
document.write(a)
document.write(b)
document.write(c)
document.write(d)
</script>
</html>
|
Usage Of Loop In Java Script:
Using a function we make a table of seven (7) we can also change the value when we call the function
<html>
<script>
function tbl(n)
{
for(i=0; i<=10; i=i+1)
{
document.write(n);
document.write("x");
document.write(i);
document.write("=");
document.write(n * i);
document.write("<br>");
}
}
tbl(7);
</script>
</html>
|
Usage of getElementById:
We make simple program using
- onMouseOver
- onMouseout
This program change the image size when the pointers is Over the image & when the Out of image.
<html>
<script>
function
sizechange()
{
a=document.getElementById("i");
a.width="420"
a.height="420"
}
function
undochange()
{
a=document.getElementById("i");
a.width="320";
a.height="320";
}
</script>
<body>
<img
id="i" src="A.jpg"
width="400" height="400"
onMouseOver="sizechange()"
onMouseOut="undochange()"/>
</body>
</html>
|
No comments:
Post a Comment