Academic Tutorials



English | French | Portugese | German | Italian
Google

Home Source Codes E-Books Downloads Contact Us About Us

JavaScript Tutorial
JavaScript Introduction
JavaScript How To
JavaScript Where To
JavaScript Variables
JavaScript If...Else Statement
JavaScript Switch Statement
JavaScript Operator
JavaScript Popup-boxes
JavaScript Function
JavaScript For-Loop
JavaScript While-loops
JavaScript Break Loops
JavaScript For..In Statement
JavaScript Event
JavaScript Try-Catch Statement
JavaScript Throw Statement
JavaScript Onerror
JavaScript Spacial Characters
JavaScript Guideline
JavaScript String
JavaScript Date Object
JavaScript Array
JavaScript Boolean Object
JavaScript Math Object
JavaScript HTML DOM Object
JavaScript Browser Detection
JavaScript Cookies
JavaScript Validation
JavaScript Animation
JavaScript Image Maps
JavaScript Timing Event
JavaScript Create Object
JavaScript Summary

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
AJAX Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PHP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
.NET (dotnet)
Microsoft.Net
XML Web Services
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills


JavaScript Where To
Previous Next

There are three ways by which we can place Javascript for use in a web page.

1. Inside the head section.

2. Within the body section.

3. In an external file.


1. Inside the head section

Java Scripts in the body section will be executed while the page loads.

Scripts that contains function go in the head section of the document. Then we can sure that the script is load before the function is called.

Example:1

<html>
 <head>
  <script type="text/javascript">
   function message()
    {
     alert("This alert box was called with the onload event")
    }
   </script>
  </head>
 <body onload="message()">
 </body>
</html>


Output

Within an HTML document the <script> tag can be placed any number of times, it is like any other tag, and like most tags <script>has to be ended with </script>. As soon as the Javascript code is loaded into the browser it is executed, sometimes we may not want that. In cases like that when the script is executed when called (most often functions) we place it in the head section.


Example:2

<html>
 <head>
   <script language="Javascript">
     ......Javascript Statements.......
   </script>
 </head>
 <body>
</body>
</html>



2. Within the body section

Scripts to be executed when the page loads go in the body section. When you place a script in the body section it generates the content of the page.


Example:3

Will execute when the page loads (when the body section of the page is reached).

<html>
 <head>
 </head>
  <body>
    <script type="text/javascript">
  document.write("This message is Display when the page loads")
   </script>
  </body>
</html>


Output
This message is Display when the page loads

JavaScripts in both the body and the head section of the HTML page:

You can place an unlimited numbers of Java Scripts in your HTML page or document, so you can have scripts in both the body and the head section of HTML page.


Example:4

<html>
 <head>
  <script type="text/javascript">
some statements
  </script>
 </head>
 <body>
  <script type="text/javascript">
   some statements
  </script>
 </body>
</html>



3. In an external file

A script section placed in either the head section or body section, links to an external javascript file. Save the file with a ".js" file extension and include everything inside the script tags. For example: document.write("Vyom Technosoft, from an external javascript file!")

The external script cannot contain the <script> tag!

Example:5

<html>
 <head>
  <script type="text/javascript" src="vyomscript1.js">
some statements
  </script>
 </head>
 <body>
  <script type="text/javascript" src="vyomscript2.js">
   some statements
  </script>
 </body>
</html>



Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previous Next

Keywords:Where to


HTML Quizes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
XML Quizes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizes
JavaScript Quiz
VBScript Quiz
AJAX Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizes
ASP Quiz
PHP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
.NET (dotnet) Quizes
Microsoft.Net Quiz
XML Web Services Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
Multimedia Quizes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Web Building  Quizes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Java Quizes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Programming Langauges Quizes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Soft Skills Quizes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz

Privacy Policy
Copyright © 2003-2008 Vyom Technosoft Pvt. Ltd., All Rights Reserved.