google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: Javascript Program

Saturday, April 2, 2016

Javascript Program


 1) EVENT DRIVEN CLIENT SIDE SCRIPT.

STEP 1 – EVENT.HTML

<html>
<head>
<title> Event driven </title>
</head>
<body>
<input type=”button” value=”Colors” OnMouseOver=window.setTimeout(“f1()”,1200);>
<script language=”javaScript”>
function f1()
{
document.bgColor=”orange”;
window.setTimeout(“f2()”,1200);
}
function f2()
{
document.bgColor=”white”;
window.setTimeout(“f3()”,1200);
}
function f3()
{
document.bgColor=”green”;
window.setTimeout(“f4()”,1200);
}
function f4()
{
document.bgColor=”purple”;
window.setTimeout(“f6()”,1200);
}
function f5()
{
document.bgColor=”cyan”;
window.setTimeout(“f6()”,1200);
}
function f6()
{
document.bgColor=”brown”;
window.setTimeout(“f7()”,1200);
}
function f7()
{
document.bgColor=”orange”;
window.setTimeout(“f1()”,1200);
f1();
}
</script>
</body>
</html>

STEP 2 – EVENT1.HTML

<html>
<head>
<title> Event driven </title>
</head>
<body onLoad=window.setTimeout(“f1()”,1200);>
<H1> This changesbackground color autometically </H1>
<script language=”javaScript”>
function f1()
{
document.bgColor=”orange”;
window.setTimeout(“f2()”,1200);
}
function f2()
{
document.bgColor=”white”;
window.setTimeout(“f3()”,1200);
}
function f3()
{
document.bgColor=”green”;
window.setTimeout(“f4()”,1200);
}
function f4()
{
document.bgColor=”purple”;
window.setTimeout(“f6()”,1200);
}
function f5()
{
document.bgColor=”cyan”;
window.setTimeout(“f6()”,1200);
}
function f6()
{
document.bgColor=”brown”;
window.setTimeout(“f7()”,1200);
}
function f7()
{
document.bgColor=”orange”;
window.setTimeout(“f1()”,1200);
f1();
}
</script>
</body>
</html>


STEP 1 - OUTPUT
















STEP 2 - OUTPUT



This Changes background color automatically

















2)TELEPHONE NUMBER AND SALARY AMOUNT VALIDATION
 <html>
<head>
<title> email </title>
<script language="JavaScript">
function validate()
{
if(telno()&&salamt())
{
alert("Acceptable");
}
else
{
alert("Not Acceptable");
}

function telno()
{ s=document.check.tel.value;
if(s==""||s.length<6||s.length>10 || isNaN(s))
{
alert("Invalid telephone number");
document.check.tel.value=" ";
document.check.tel.focus();
return false;
}
else
{ return true; }
}

function salamt()
{ s=document.check.sal.value;
if(s=="" || s.length<4 || s.length>10 || isNaN(s))
{
alert("Invalid salary.");
document.check.sal.value=" ";
document.check.sal.focus();
return false;
}
var dot=s.indexOf(".")
if((dot!=-1)&&(s.charAt(dot+3)!=""))
{
alert("Enter salary upto 2 decimal places.");
document.check.sal.value=" ";
document.check.sal.focus();
return false;
}
else
{ return true; }
}

}
</script>
</head>
<body>
<form name=check>
Enter your telephone number <input type=text name=tel> <br>
Enter your salary <input type=text name=sal> <br>
<input type=button value="submit" onClick=validate();>
</form>
</body>
</html>
 
Enter your telephone number
Enter your salary
 


3)USERNAME AND PASSWORD VALIDATION USING JAVASCRIPT.

 
<html>
<head>
<title> email </title>
<script language="JavaScript">
function validate()
{
if(user()&&pword())
{
alert("Acceptable");
}
else
{
alert("Not Acceptable");
}

function user()
{ s=document.check.uname.value;
if(s==""||s.length<6||s.length>10)
{
alert("Uername should be more than 6 and less than 10 char.");
document.check.uname.value=" ";
document.check.uname.focus();
return false;
}
for(i=0;i<s.length;i++)
{
var ch=s.charAt(i);
if((ch<'a'||ch>'z') && (ch<'A'||ch>'Z') && (ch<'0'||ch>'9'))
{
alert("Uername accepts letters and digits.");
document.check.uname.value=" ";
document.check.uname.focus();
return false;
}
else
{ return true; }
}
}

function pword()
{ s=document.check.pass.value;
if(s==""||s.length<6||s.length>10)
{
alert("Password should be more than 6 and less than 10 char.");
document.check.pass.value=" ";
document.check.pass.focus();
return false;
}
for(i=0;i<s.length;i++)
{
var ch=s.charAt(i);
if((ch<'a'||ch>'z') && (ch<'A'||ch>'Z') && (ch<'0'||ch>'9'))
{
alert("Password accepts letters and digits.");
document.check.pass.value=" ";
document.check.pass.focus();
return false;
}
else
{ return true; }
}

}
}
</script>
</head>
<body>
<form name=check>
Enter username: <input type=text name=uname> <br>
Enter password : <input type=text name=pass><br>
<input type=button value="submit" onClick=validate();>
</form>
</body>
</html>

 

OUTPUT


Enter username

 
Enter password


 


4)  E-MAIL ADDRESS VALIDATION USING JAVASCRIPT.

 
<html>
<head>
<title> email </title>
<script language="JavaScript">
function validate()
{
m=document.mail.email.value;
apos=m.indexOf("@");
dotpos=m.indexOf(".");
rat=m.indexOf("@",apos+1);
if(apos<1||dotpos-apos<2||rat!=-1)
{
alert("Not a valid e-mail address");
}
else
{ alert(" valid e-mail address");
}
}

</script>
</head>
<body>
<form name=mail>
Enter your E-mail address :<input type=text name=email> <br>
<input type=button value="check email" onClick=validate();>
</form>
</body>
</html>

OUTPUT


Enter your E-mail addresss
 

 


अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...