JavaScript
  Home arrow JavaScript arrow Page 3 - Javascript: the Beginning
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Javascript: the Beginning
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2007-10-29

    Table of Contents:
  • Javascript: the Beginning
  • Adding Javascript to an HTML Page
  • Putting JavaScript in its Place
  • Variables

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Javascript: the Beginning - Putting JavaScript in its Place


    (Page 3 of 4 )

    Having a similar name to a big-shot like Java has given JavaScript a big head. Quite frankly, it needs to be put in his place. But where is that place you ask? Hold on a second and I'll show you.

    There are three places you can put JavaScript. Well, there's also a fourth if your boss really ticks you off, but that's for another tutorial.


    • Head Section: This is for scripts that contain functions and need to be loaded prior to the function being called.

       

    • Body Section: This is for scripts that need to be executed when the page loads.

       

    • Externally: If you have a script that runs across multiple pages and do not wish to write the script on each page, you can store the script externally.

    It's worth noting, in case this list gives you the wrong idea, that you can use multiple scripts throughout your page.

    Here are some examples of each placement:


    <html>

    <head>

    <script type="text/javascript"> // don't forget this line

    YOUR SCRIPT HERE //this is where your script would go

    </script>

    </head>

    <body>

    </body>

    </html>

    The above is an example of placing a script in the HEAD section.


    <html>

    <head>

    </head>

    <body>

    <script type="text/javascript"> // don't forget this line

    YOUR SCRIPT HERE //this is where your script would go

    </script>

    </body>

    </html>

    That was an example of storing scripts in the BODY section. And lastly:


    <html>

    <head>

    <script src="nameofthescript.js"></script>

    </head>

    <body>

    </body>

    </html>

    The above shows you how to call a script that is external. Note that where you place this tag depends on what type of script it is. If it needed to be loaded with the page, you would have placed it in the body section instead. Also be aware that the external script can not contain the <script> tag.

    One more thing. This is how it looks to use JavaScript in multiple sections.


    <html>

    <head>

    <script type="text/javascript">

    YOUR SCRIPT HERE

    </script>

    </head>

    <body>

    <script type="text/javascript">

    YOUR SCRIPT HERE

    </script>

    </body>

    </html>

    More JavaScript Articles
    More By James Payne


       · Thanks for dropping by and reading my article. In this tutorial we discuss how to...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT