Client Side Scripting (JavaScript)

Client Side Scripting (JavaScript)

·        Simple JavaScript program for declaring variable.

Var.html

<html>

<head>

<title></title>

</head>

<body>

<script language="javascript">

var name="National";

var a=10;

document.write(name+"<br>");

document.write(a);

</script>

<p> this example declares a variable, assign a value to it, and then display the variable. </p>

</body>

</html>

·        Simple JavaScript program to demonstrate Arithmetic Operators.

Arithmetic.html

<html>

<head>

<title></title>

</head>

<body>

<script language="javascript">

var a,b;

a=5;

b=2;

document.write("Value of a is : "+a+" Value of b is : "+b+"<br>")

c=a+b;

document.write("Addition of a and b is : "+c+"<br>");

c=a-b;

document.write("Sunstraction of a and b is : "+c+"<br>");

c=a*b;

document.write("Multiplication of a and b is : "+c+"<br>");

c=a/b;

document.write("Division of a and b is : "+c+"<br>");

</script>

</body>

</html>

·        Simple JavaScript program to demonstrate concatenation operator.

Concat.html

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<h3>+ as a concatination operator.</h3>

<script type="text/javascript">

var a=15+"Hello";

var b=15+7+"Hello";

document.write(" <br> Value of a is : "+a+"<br>");

document.write("Value of b is : "+b);

</script>

</body>

</html>

·        Simple JavaScript Program to demonstrate relational operators.

Relation.html

<html>

<head>

<title></title>

</head>

<body>

<script language="javascript">

var a,b;

a=prompt("Enter the first number","");

b=prompt("Enter the second number","");

document.write("Value of a is : "+a+" value of b is : "+b+"<br>");

if (a>b)

{

document.write("A is greater than B");   

}

else if(a < b)

{

document.write("B is greater than a")

}

else

{

document.write("B is equal to A");          

}

</script>

</body>

</html>

·        Simple JavaScript Program to demonstrate logical operators.

Leap.html

<html>

<head>

<title></title>

</head>

<body>

<Script language="JavaScript">

var z;

z=prompt("Enter an year"); z=parseInt(z);

if(z % 4 == 0 && (z % 100 !=0 || z % 400 == 0))

{

document.write(z + " is leap year." + "<br>");

}

else

{

document.write(z + "is not a leap year." + "<br>");

}

</script>

</body>

</html>

·        Simple JavaScript program to demonstrate unary operator.

Unary.html

<html>

<head>

<title></title>

</head>

<body>

<script language="javascript">

var x=10;

var n,m,y=10;

++x   // 11

document.write("value of x after increment is : " + x + "<br>")

x--  // 10

document.write("value of x after Decrement is : " + x + "<br>")

 y++   // 10

//document.write("value of n after post increment is : " + n + "<br>")

document.write("value of y after post increment is : " + y + "<br>")

++y   // 12

document.write("value of m after pre increment is : " + y)

</script>

</body>

</html>

·        Simple JavaScript program to calculate area of circle.







Circle.html

<!DOCTYPE html>

<html>

<head>

<title>Area of Circle</title>

</head>

<body bgcolor="aqua">

<h1>Program to find area of circle</h1>

<script type="text/javascript">

var r,area;

r=prompt("Enter the radius of circle");

area=3.14*r*r;

document.write("Radius of circle is : "+r+"<br>");

document.write("Area of circle is : "+area);

</script>

</body>

</html>

·        Simple JavaScript program to demonstrate if …. else statement.

Even.html

<html>

<head>

<title> Odd and Even Numbers </title>

</head>

<body bgcolor="orange">

<script type="text/javascript">

var no;

no=prompt("Enter your value");

no=parseInt(no);

if(no%2==0)

{

alert("Entered value is even");

}

else {

alert("Entered value is odd");

}

</script>

</body>

</html>

·        Simple JavaScript program to demonstrate User Defined Function.

Userdef.html

<!DOCTYPE html>

<html>

<head>

<title>User Defined Function</title>

<script language="javascript">

function show()

{

document.write("Welcome to userdefine function");

}

</script>

</head>

<body bgcolor="orange">

<h3>Use of function in javascript</h3>

<script language="javascript">

show(); // calling of function

</script>

</body>

</html>

·        Simple JavaScript program to demonstrate various mouse events.

Mouseeve.html

<html>

<head>

<title></title>

<script language="javascript">

function mclick()

{

alert("Hey...., You just click mouse button");

}

function mdown()

{

alert("This is onmousedown event");

}

function mover()

{

document.bgColor="Orange";

}

function mout()

{

document.bgColor="PINK";

}

function mup()

alert("This is onmouseup event");

}

</script>

</head>

<body>

<p onclick="mclick()">Click here to triggered onclick event of mouse</p>

<p onmouseover="mover()" onmouseout="mout()">Just move the mouse pointer over this text to change background color to orange and remove the pointer from text to change background color to pink</p>

<input type="button" value="Onmousedown" onmousedown="mdown()"><br>

<input type="button" value="Onmouseup" onmouseup="mup()">

</body>

</html>

·        Simple JavaScript program to demonstrate various keyboard events.

Keyeve.html

<!DOCTYPE html>

<html>

<head>

<title>Keyboard Events</title>

<script type="text/javascript">

function keypress()

{

alert("You press a key inside text field");

}

function keydown()

{

var x=document.f1.t2;

x.value=x.value.toUpperCase();

}

function keyup()

{

document.f1.t3.style.backgroundColor="yellow";

}

</script>

</head>

<body>

<form name="f1">

onkeypress:<input type="text" size=25 name="t1" onkeypress="keypress()"><br>

onkeydown :<input type="text" size=25 name="t2" onkeydown="keydown()"><br>

onkeyup   :<input type="text" size=25 name="t3" onkeyup="keyup()"><br>

</form>

</body>

</html>



0 comments:

Post a Comment