Javascript is typically placed within three areas of a web page:
- Header Section: Code for functions, and shared variable declaration/initialization.
- Body Section: Code which executes as the page is loaded, producing output which is woven into the page.
- End Section: Code which calls initialization routines, e.g. timers.
Below is a code sample which illustrates several techniques:
<html>
<head>
<script language="javascript">
<!--
function f_timer()
{
imageidx ++ ;
if (imageidx==8)
{
imageidx=0
} ;
}
// -->
</script>
</head>
<body>
<form>
Paragraph 1 : This is some sample text located in the body of the page.<br>
This example illustrates the ability to embed Javascript calls within the body of a form.
<script language="javascript">
<!--
document.write("<hr>" + "This was written by Javascript" + "<hr>");
// -->
</script>
Paragraph 2 : This is some sample text located in the body of the page.<br>
This example illustrates the ability to embed Javascript calls within the body of a form.
<script language="javascript">
<!--
document.write("<h2>" + "This was written by Javascript also" + "</h2>");
// -->
</script>
Paragraph 3 : This is some sample text located in the body of the page.<br>
This example illustrates the ability to embed Javascript calls within the body of a form.
</form>
</body>
<script>
<!--
timerID = setTimeout("f_timer()", 1000);
//-->
</script>
</html>
|
|