JavaScript
  Home arrow JavaScript arrow Page 2 - 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 - Adding Javascript to an HTML Page


    (Page 2 of 4 )

    Traditional programming tutorials want you to write a program that prints the phrase, "Hello World!" to the screen. It's similar to learning your first song on guitar or bass. They always teach you Smoke on the Water. Always.

    Well not today my friend. Today we break away from tradition.


    <html>

    <body>

    <script type="text/javascript">

    document.write("I'm here to kick butt and chew bubble gum. And I am all out of bubble gum...")

    </script>

    </body>

    </html>

    The above code will print the following:

      I'm here to kick butt and chew bubble gum. And I am all out of bubble gum...

    The tag <script type="text/javascript"> tells the browser that the following code is JavaScript. If you were to leave this code out, this is what would have printed:

      document.write("I'm here to kick butt and chew bubble gum. And I am all out of bubble gum...")

    The portion of the code that begins document.write is the command used to print text to the monitor.

    Formatting Text

    Just as we can embed JavaScript into our HTML, we can place HTML inside of our JavaScript. Here is an example:


    <html>

    <body>

    <script type="text/javascript">

    document.write("I don't like gum. I <i>love</i> it.")

    </script>

    </body>

    </html>

    This results in the following being printed to your screen:

      I don't like gum. I love it.

    Any Comments? Keep 'em to Yourself

    Unless they are good comments that is. If you have those send them on in. Maybe I will get that raise from $5.50 an hour to $6.00 (*fingers crossed*) after all.

    You use comments in JavaScript (and any other programming language) to leave notes to yourself or future programmers regarding your code. It's a lot easier when you have to go back and fix a mistake if you can see a comment and know right off the bat what you were intending to do with it.

    You use two forward-slashes (//) to comment in JavaScript. When the browser sees these, it ignores any text following it on that line.


    <html>

    <body>

    <script type="text/javascript">

    document.write("<i>Hello</i>") //This is a comment.

    // Here is another comment

    </script>

    </body>

    </html>


    The above code would simply print Hello to your monitor.

    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 1 hosted by Hostway
    Stay green...Green IT