Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 16-10-2009, 10:50 PM   #1 (permalink)
Right Off the Assembly Line
 
Dharmpal Singh's Avatar
 
Join Date: Jul 2006
Posts: 13
Lightbulb Javacsript Help


Code:
<html>
<head>
<script type="text/javascript">
function blinking_header()
{
if (!document.getElementById('blink').style.color)
	{
	document.getElementById('blink').style.color="red";
	}
if (document.getElementById('blink').style.color=="red")
	{
	document.getElementById('blink').style.color="black";
	}
else
	{
	document.getElementById('blink').style.color="red";
	}
timer=setTimeout("blinking_header()",100);
}

function stoptimer()
{
clearTimeout(timer);
}
</script>
</head>

<body onload="blinking_header()" onunload="stoptimer()">
<h1 id="blink">Blinking header</h1> 
</body>

</html>
Can Any Body explain me these code line by line .
Dharmpal Singh is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 20-11-2009, 12:24 PM   #2 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: Javacsript Help

Quote:
Can Any Body explain me these code line by line
Well Let me try....!!

Code:
<html>
<head>
Starting tag of HTML and HEAD part

Code:
<script type="text/javascript">
Defines the script type which is js in this case

Code:
function blinking_header()
a user defined function named blinking_header is starting


Code:
if (!document.getElementById('blink').style.color)
document means the HTML page(currect page/doc). getElementById is a inbuilt func which gets element id where we passed blink which is a element(we'll see it later) to get its id.
.style is refers to the style of blink
.color is a property of style.
and a !(not) is added to the beginning.

This means if thr is no color in blink then.....

Code:
document.getElementById('blink').style.color="red";
Again we r fetching the id of element blink which is within document and setting its colour to red.

Code:
if (document.getElementById('blink').style.color=="red")
Now we r checking whether the colour of blink is red


Code:
document.getElementById('blink').style.color="black";
If the avobe condition is true thn we r setting thr colour of blink to Black

Code:
else
	{
	document.getElementById('blink').style.color="red";
	}
Else means if the colour of blink is not red then we r setting the colour to red.
It is the else part of 2nd if.


Code:
timer=setTimeout("blinking_header()",100);
Now we r setting a clock which will execute this blinking_header() func every 100secs(i forgot is it millisec/sec) and the timer variable will keep track of it.

And with this the function blinking_header() ends.

Code:
function stoptimer()
{
clearTimeout(timer);
}
Now a new function starts named stoptimer()
and its stopping the timer i.e the clock.
clearTimeout is an inbuilt function where we passed timer variable which was keeping track of the clock.


Code:
</script>
</head>
The script and head part ends. The scripts needs to be always declared in head part.

Code:
<body onload="blinking_header()" onunload="stoptimer()">
<h1 id="blink">Blinking header</h1> 
</body>

</html>
The body of HTML is starting and onload event(i.e when the page loads i.e startup/releaded) it's calling blinking_header() function and onunload event(i.e when the page unloads(when the page is being unload i.e closed) it's calling the stoptimer() functn.

Means when the page will load the blinking_header() function starts and keeps changing the colour of blink element from red to black and vice-versa after a desired time(i.e 100 in this case) and continues it.

And when the page is closed this action stops as the timer is stopped within the fiunction.

And now we can see that what we are calling element blink is a header of H1.

Tats all.....!!

I know my eng is painfull plz manage....!!

Others plz correct me if I'm wrong.
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Charan
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 03:11 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2