PRACTICAL LIST OF WEB TECHNOLOGY-2
1)
Write
a Program in Javascript to Find Fibonacci Scries.
<!DOCTYPE
html>
<html>
<head>
<title>Welcome to
javascript</title>
</head>
<body>
<script
type="text/javascript">
document.write("<br><h1>
The given fibonacci scries is </h1></br>")
var
var1=0;
var
var2=1;
var
var3;
var
num =prompt("enter the limit to genrate fibonacci no.",0);
document.write(var1+"<br/>");
document.write(var2+"<br/>");
for(var
i=3;i<=num;i++)
{
var3=var1+var2;
var1=var2;
var2=var3;
document.write(var3+"<br/>");
}</script>
</body>
</html>
2) Write a Program in Javascript
to display a calculator.
<!DOCTYPE
html>
<html>
<head>
<title> demo of
calculator</title>
<script
type="text/javascript">
function d(val)
{
document.getElementById('result').value+=val;
// body...
}
function solve()
{
var
value1=document.getElementById('result').value;
let res=eval(value1);
document.getElementById('result').value=res;
}
function cleard()
{
document.getElementById('result').value="";
}
</script>
<style
type="text/css">
body,html{
matgin:0px;
}
input[type="button"]
{
border: none;
width: 100%;
outline: none;
}
#wrap
{
margin: 10%;
}
</style>
</head>
<body>
<div
id='wrap'>
<table bgcolor="1">
<tr>
<td
colspan="3"><input type="text"
Id="result"/></td>
<td><input
type="button" value="C"
onclick="cleard()"/></td>
</tr>
<tr>
<td><input
type="button" value="1"
onclick="d('1')"></td>
<td><input
type="button" value="2"
onclick="d('2')"></td>
<td><input
type="button" value="3"
onclick="d('3')"></td>
<td><input
type="button" value="+"
onclick="d('+')"></td>
</tr>
<tr>
<td><input
type="button" value="4"
onclick="d('4')"></td>
<td><input
type="button" value="5"
onclick="d('5')"></td>
<td><input
type="button" value="6"
onclick="d('6')"></td>
<td><input
type="button" value="-"
onclick="d('-')"></td>
</tr>
<tr>
<td><input
type="button" value="7"
onclick="d('7')"></td>
<td><input
type="button" value="8"
onclick="d('8')"></td>
<td><input type="button"
value="9" onclick="d('9')"></td>
<td><input
type="button" value="/"
onclick="d('/')"></td>
</tr>
<tr>
<td><input
type="button" value="*"
onclick="d('*')"></td>
<td><input
type="button" value="0"
onclick="d('0')"></td>
<td><input
type="button" value="."
onclick="d('.')"></td>
<td><input
type="button" value="="
onclick="solve()"></td>
</tr>
</table>
</div>
</body>
</html>
3)Write
a Program in Javascript to Display current date.
<!DOCTYPE
html>
<html>
<head>
<title> current
date</title>
</head>
<body>
<script
type="text/javascript">
var dt=Date();
document.write("Date:"+dt);
</script>
</body>
</html>
4) Write a Program in Javascript to Print the Following
Output
*
**
***
****
*****
<!DOCTYPE
html>
<html>
<head>
<title>display</title>
</head>
<body>
<script
type="text/javascript">
var i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
document.write("*");
}
document.write("<br/>");
}
</script>
</body>
</html>
5)
Write a
Program to Create string object
In Javascript .
<!DOCTYPE
html>
<html>
<head>
<title>string
object</title>
<script
type="text/javascript">
var str=prompt("enter any
string")
</script>
</head>
<body>
<script
type="text/javascript">
document.write("superscript the
text is ="+str());
</script>
</body>
</html>
6) Write a Program in
Javascript to print following output.
1
12
123
1234
12345
1234
123
12
1
<!DOCTYPE
html>
<html>
<head>
<title>number</title>
</head>
<body>
<script
language="JavaScript">
var
i,j;
for (i=1;i<=5;i++)
{
for (j=1;j<=i;j++)
{
document.write(+j);
}
document.write("<br/>");
}
for (i=4;i>=1;i--)
{
for
(j=1;j<=i;j++)
{
document.write(+j);
}
document.write("<br/>");
}
</script>
</body>
</html>
7)Write a program in javascript for
validation of user id in registration form
<!DOCTYPE html>
<html
lang="en"><head>
<h1>Registration Form</h1>
<meta charset="utf-8">
<title>JavaScript Form Validation
using a sample registration form</title>
<meta name="keywords"
content="example, JavaScript Form Validation, Sample registration
form" />
<meta name="description"
content="This document is an example of JavaScript Form Validation using a
sample registration form. " />
<link rel='stylesheet' href='js-form-validation.css'
type='text/css' />
<script
src="sample-registration-form-validation.js"></script>
</head>
<script>
function validateForm() {
var x = document.forms["myForm"]["userid"].value;
if (x == "") {
alert(" userid must be filled out");
return false;
}
}
</script>
<form name="myForm"
action="/action_page.php" onsubmit="return validateForm()"
method="post">
<body
onload="document.registration.userid.focus();">
<form name='registration'
onSubmit="return formValidation();">
<ul>
<li><label
for="userid">User id:</label></li>
<li><input
type="text" name="userid" size="12"
/></li>
<li><label
for="passid">Password:</label></li>
<li><input
type="password" name="passid" size="12"
/></li>
<li><label
for="username">Name:</label></li>
<li><input
type="text" name="username" size="50"
/></li>
<li><label
for="address">Address:</label></li>
<li><input
type="text" name="address" size="50"
/></li>
<li><input
type="submit" name="submit" value="Submit"
/></li>
</ul>
</form>
</body>
</html>
8)Write
a program in javascript to validation of
form
<!DOCTYPE html>
<html>
<head>
<script>
function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if (x == "") {
alert(" Name must be filled out");
return false;
}
}
</script>
</head>
<body>
<form name="myForm"
action="/action_page.php" onsubmit="return validateForm()"
method="post">
<h1>validation form</h1>
Name: <input type="text"
name="fname"><br/><br/>
email id: <input type="email" name="email"><br/><br/>
password: <input type="password"
name="password"><br/><br/>
<input type="submit" value="Submit">
</center></form>
</body>
</html>
9) Write a program
in javascript to amstrong number.
<!DOCTYPE html>
<html>
<head>
<title>using javascript</title>
</head>
<body
bgcolor="#ffffff">
<Script
language="JavaScript">
var num,sum,org;
num=prompt("enter
the no.");
num=parseInt(num);
org=num;
document.write("<br><br>");
sum=0;
do
{
sum=sum+(num%10)*(num%10)*(num%10);
num=parseInt(num/10);
}
while(num!=0);
if(sum==org)
document.write("ARMSTRONG
NUMBER IS="+sum);
else
document.write("
NUMBER IS NOT ARMSTRONG");
</Script>
</body>
</html>
10)Write a program in javascript
to find the given number is even or odd.
<!DOCTYPE
html>
<html>
<head>
<title>odd even </title>
</head>
<body>
<Script
language="JavaScript">
var num;
num=prompt("enter the no.");
num=parseInt(num);
if(num%2==0)
document.write(num+"
is Even");
else
document.write(num+
"<h1><b>is Odd </h1></b>");
</Script>
</body>
</html>
l
11)
Write a
program in javascript to display
the factorial number.
<!DOCTYPE html>
<html>
<head>
<title>factorial number</title>
<body>
<Script language="JavaScript">
function factorial(num)
{
var fact,i;
fact=1;
for(i=1;i<=num;i++)
fact=fact*i;
document.write("factorial of "+num+"is="+fact);
}
</Script>
</head>
<body>
<Script
language="JavaScript">
var num;
num=prompt("enter the number");
document.write("<br><br>
<br>");
factorial(num);
</Script>
</body>
</html>
12) Write a program in javascript printing a number 1 to 10.
<!DOCTYPE
html>
<html>
<head>
<title>print 1 to 10 number
</title>
</head>
<body>
<p
id="demo"></p>
<script>
var
text ="";
var
i;
for(i=1;i<=10;i++)
{
text+=+i+"<br>"
}
document.getElementById("demo").innerHTML=text;
</script>
</body>
</html>
Comments
Post a Comment