0% found this document useful (0 votes)
62 views5 pages

Use of Setinterval Method

The document demonstrates the use of setInterval() method to display digital clock by updating time values every second. It uses setInterval() to call the show_time() function which gets current time and displays it in text fields. A button is used to start and stop the timer using clearInterval().

Uploaded by

Rishabh Tiwari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views5 pages

Use of Setinterval Method

The document demonstrates the use of setInterval() method to display digital clock by updating time values every second. It uses setInterval() to call the show_time() function which gets current time and displays it in text fields. A button is used to start and stop the timer using clearInterval().

Uploaded by

Rishabh Tiwari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Use Of setInterval() method:

<html> <head> <title>DHTML</title> <script language="Javascript"> function show_time() { var todate=new Date(); var hh=todate.getHours(); var mm=todate.getMinutes(); var ss=todate.getSeconds(); document.f.t1.value=hh; document.f.t2.value=mm; document.f.t3.value=ss; } function show_t() { ref=setInterval("show_time()",1000); } function stop_t() { clearInterval(ref); } </script> </head> <body bgcolor="lightgreen"> <form name="f"> <h2>Digital Clock</h2> HH <input type="text" name="t1" value="">: MM <input type="textbox" name="t2" value="">: SS <input type="text" name="t3" value=""><br><br> <input type="button" name="b1" value="Show Time" onclick="show_t()"> <input type="button" name="b2" value="Stop Time" onclick="stop_t()"> </form> </body> </html>

OUTPUT:

Use Of setTimeout() method:


<html> <head> <title>Timeout</title> <script language="Javascript"> function show_photo() { setTimeout(show(),2000); } function show() { document.write("<img src=D:\223_tycs\web designing\myphoto.jpg alt=photo height=200 width=150>"); } </script> </head> <body> <input type="button" value="click me" onclick="show_photo()"> </body> </html>

OUTPUT:

Use Of getElementById() method:


<html> <head> <title>Bye Bye</title> </head> <script language="Javascript"> function show_text() { document.getElementById("one").innerHTML="Welcome to DHTML"; document.getElementById("one").style.color="magenta"; } function change_text() { document.getElementById("one").innerHTML="Bye Bye"; document.getElementById("one").style.color="red"; } </script></head> <body bgcolor="lightgreen" text="blue"> <center> <h1 id="one" onmouseover="show_text()" onmouseout="change_text()"> I am Meghna</h1></center> </body> </html>

OUTPUT:

Use Of Cookies:
(a)cookie.html <html> <head> <title>Handling Cookie in JavaScript</title> <script language="Javascript"> document.cookie="class=tycs"; document.cookie="degree=computer science"; alert(document.cookie); </script> </head> <body bgcolor="pink"> <h2>Cookie Created</h2> <a href ="2cookie.html">VIEW COOKIE</a> </body> </html> (b)2cookie.html <html> <body> <script language="Javascript"> document.writeln("<h2 style=color:green>" + document.cookie + "</h2>"); </script> </body> </html>

OUTPUT:

You might also like