11th Class . IT(Information Technology) Skill Set 3 - Javascript. Sop-4
STD: 11th. Subject: IT(Information Technology)
Client Side Scripting (JavaScript)
Skill Set 3 - Javascript
SOP 4 : Create Event Driven Javascript Programs For The Following Using Appropriate Variables, Javascript Inbuilt Functions And controls Structures.
To accept number and validate if the given value is a number or not by clicking
on the button.
To calculate addition and division of two numbers.
Solution :
To accept number and validate if the given value is a number or not by clicking on the button.
<!DOCTYPE html>
<html>
<head>
<title>sop4</title>
<script language=javascript>
function val()
{
n=f1.v.value
if(!isNaN(n))
document.write(n+" is a number")
else
document.write(n+" is a not number")
}
</script>
</head>
<body>
<form name=f1>
Enter Value:- <input type=text name=v>
<br><br>
<input type=Submit value=Submit onClick=val()>
</form>
</body>
</html>
Output:
To calculate addition and division of two numbers.
<!DOCTYPE html>
<html>
<head>
<title>sop4</title>
<script language=javascript>
function add()
{
num1=parseInt(f1.n1.value)
num2=parseInt(f1.n2.value)
add=num1+num2
alert("Addition = " +add)
}
function div()
{
num1=parseInt(f1.n1.value)
num2=parseInt(f1.n2.value)
div=num1/num2
alert("Division = " +div)
}
</script>
</head>
<body>
<form name=f1>
<b>1st Number:- <input type=text name=n1>
<br><br>
<b>2nd Number:- <input type=text name=n2>
<br><br>
<input type=button value=Addition onClick="add()">
<input type=button value=Divide onClick="div()">
</form>
</body>
</html>
Comments
Post a Comment