Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Javascript Coding

Uploaded by

riya.arulekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Javascript Coding

Uploaded by

riya.arulekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

JAVASCRIPT

--------------------------------------------------------------------------------------------------------------------------------------

COLOR.HTML

<!DOCTYPE html>

<html>

<head>

<title>

Background Colurs

</title>

</head>

<body>

<h1 align="center">7 Different & visibly distinct Background colors</h1>

<form name="frml">

<center>

<input type="button" name="btncolor" value="Change Colurs" onmouseover="f1()"

<input type="button" name="btnmsg" value="Message Display" onclick="msg()">

</form>

</body>

<script type="text/javascript">

function f1()

document.bgColor="red";
window.setTimeout("f2()",1500);

function f2()

document.bgColor="green";

window.setTimeout("f3()",1500);

function f3()

document.bgColor="pink";

window.setTimeout("f4()",1500);

function f4()

document.bgColor="orange";

window.setTimeout("f5()",1500);

function f5()

document.bgColor="skyblue";

window.setTimeout("f6()",1500);

function f6()

document.bgColor="voilet";

window.setTimeout("f7()",1500);

function f7()

document.bgColor="aqua";

window.setTimeout("f8()",1500);
}

function msg()

window.status="Display of 7 differet color";

</script>

</html>
EMAIL.HTML
<html>

<body>

<form name="frm1">

Enter Name

<input type="text" name="t1"><br><br>

Enter Address<br>

<textarea name="t2" placeholder="PERMENANT ADDRESS"></textarea><br><br>

Enter Telephone Number

<input type="tel" maxlength="10"><br><br>

Enter Email Address

<input type="email" name="t3" pattern="[A-Z a-z]{5}-[@]{1}-[.]{1}"


placeholder="lax2107@gmail.com"><br><br>

<input type="button" name="b1" value="Submit" onclick="chk()">

</form>

</body>

<script type="text/javascript">

function chk()

var x=frm1.t3.value;

var atpos=x.indexOf("@");

var lastat=x.lastIndexOf("@");

var firstdot=x.indexOf(".");

var dotpos=x.lastIndexOf(".");

if(atpos<1||dotpos<atpos+211||dotpos+2>=x.length||firstdot<atpos||atpos<lastat)

alert("Not a valid email address");

frm1.t3.focus();

else

alert("Email address is accepted");

return true;

</script>

</html>
--------------------------------------------------------------------------------------------------------------------------------------

CODE.HTML
<!DOCTYPE html>

<html>

<head>

<title>String function</title>

</head>

<body>

<form name="frm1">

Enter Your name

<input type="text" name="t1"><br><br>

<input type="button" name="btncheck" value="Count Vowels" onclick="cnt()">

</form>

</body>

<script type="text/javascript">

function cnt()

var s,i,ch,c;

c=0;

s=frm1.t1.value;

for(i=0;i<=s.length;i++)

ch=s.charAt(i);
if(ch=="A" || ch=="a" || ch=="E" || ch=="e" || ch=="T" || ch=="i" || ch=="O" || ch=="o"
|| ch=="U" || ch=="u")c++;

alert("Number of Vowels in string are "+ c);

</script>

</html>
PALIMDOME.HTML
<!DOCTYPE html>

<html>

<head>

<title>Palindrome</title>

</head>

<body>

<form name="frm1">

Enter your name

<input type="text" name="t1"><br><br>

<input type="button" name="btncheck" value="Check Palindrome" onClick="chk()">

</form>

</body>

<script type="text/javascript">

function chk()

var a,s,i,ch,n;

a=frm1.t1.value;

s=a.toLowerCase();

n=s.length;

var p=1;

for(i=0; i<n/2;i++)

if(s.charAt(i)!= s.charAt(n-1-i))

p=0;

break;
}

if(p==1)

alert("String is Palindrome");

else

alert("String is palindrome")

</script>

</html>
CELSIUS.HTML

<!DOCTYPE html>

<html>

<head>

<title>Celsius to Fahrenheit converter</title>

</head>

<body>

<h2>javascript to Fahrenheit Converter</h2>

<p>Insert a number into one of the input fields below:</p>

<p><input type="text" id="c" onkeyup="convert('C')"> Degrees Celsius</p>

<p><input type="text" id="f" onkeyup="convert('F')"> degrees Fahrenheit</p>

<p>Note that the <b>Math.round()</b> method is used, so that the result will be returned as an
integer.</p>

<script type="text/javascript">

function convert(degree)

var x;

if (degree == "C")

{
x = document.getElementById("c").value* 9/5 +32;

document.getElementById("f").value = Math.round(x);

else

x = (document.getElementById("f").value -32) *5/9;

document.getElementById("c").value = Math.round(x);

</script>

</body>

</html>
GRADE.HTML

<html>

<body>

<form name="frm1">

Enter Marks of English

<input type="number" name="t1"><br><br>

Enter Marks of Maths

<input type="number" name="t2"><br><br>

Enter Marks of Physics

<input type="number" name="t3"><br><br>

Enter Marks of Chemistry

<input type="number" name="t4"><br><br>

Enter Marks of IT

<input type="number" name="t5"><br><br>

<input type="button" name="btnclick" value="Print Grade" onClick="grade()">

</form>

</body>
<script type="text/javascript">

function grade()

{ var m1,m2,m3,m4,m5,a;

m1=frm1.t1.value;

m2=frm1.t2.value;

m3=frm1.t3.value;

m4=frm1.t4.value;

m5=frm1.t5.value;

a=(m1+m2+m3+m4+m5)/5;

alert("Average Marks of Student is "+a);

if(a>90)

alert("Grade A");

else

if(a>=81)

alert("Grade B");

else

if(a>=71)

alert("Grade C");

else

{ if(a=61)

alert("Grade D");

else

alert("Grade F");

</script>

</html>
DATE.HTML

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript">

function GetDays(i_Date1, i_Date2)

var str = i_Date1;

var day = str.slice(0, 2);

var month = str.slice(3, 5);

var year = str.slice(6, 10); // This is the first date

var dt1 = new Date(month + "/" + day + "/" + year);

var str1 = i_Date2;

var day1 = str1.slice(0, 2);

var month1 = str1.slice(3, 5);

var year1 = str1.slice(6, 10); // This is the second date

var dt2 = new Date(month1 + "/" + day1 + "/" + year1);

var one_day = 1000 * 60 * 60 * 24;


var date1_ms = dt1.getTime();

var date2_ms = dt2.getTime();

var difference_ms = date2_ms - date1_ms;

document.writeln(Math.round(difference_ms / one_day));

</script>

</head>

<body>

<form name="form_task">

Date1:<input type="text" name="d1" placeholder="dd/mm/yyyy"><br><br>

Date2:<input type="text" name="d2" placeholder="dd/mm/yyyy"><br><br>

<input type="button" value="Submit" onclick="GetDays(form_task.d1.value,


form_task.d2.value)">

</form>

</body>

</html>

You might also like