JavaScript
  Home arrow JavaScript arrow Page 3 - The Power of Javascript: An Introduction
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 
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

The Power of Javascript: An Introduction
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 13
    2005-06-28

    Table of Contents:
  • The Power of Javascript: An Introduction
  • Meet Javascript
  • The Hello World Example
  • Hello World? What's going on?

  • 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


    The Power of Javascript: An Introduction - The Hello World Example


    (Page 3 of 4 )

    Let's take a look at your first Javascript example, the Hello World example. Write (or copy) the following code into a file with the extension .html as any other Web page you develop.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Hello World</title>
    <script language="JavaScript" type="text/javascript">
    window.alert("Hello World, from the head element");
    </script>
    </head>
    <body>
    <script language="JavaScript" type="text/javascript">
    window.alert("Hello World, from the body element");
    </script>
    </body>
    </html>

    Fire up your IE6 Browser (or any browser you like to use for this example, like Netscape 7.2 or Mozilla Firefox 1.3) and you will get the following message box as the result:

    Click on OK and another message box will show up:

    And here's the Web page itself. There's no text or any other thing on the page because we didn't include any HTML elements that can be displayed to the page:

    Before we discuss your first Javascript example, let's extend it a little bit. Modify your Web page to contain the following code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Hello World</title>
    <script language="JavaScript" type="text/javascript">
    window.alert("Hello World, from the head element");
    </script>
    </head>
    <body>
    <script language="JavaScript" type="text/javascript">
    window.alert("Hello World, from the body element");
    </script>
    <h1>
    <script language="JavaScript" type="text/javascript">
    document.write("Hello Javascript");
    </script>
    </h1>
    </body>
    </html>

    Reload the Web page and you will get the same two message boxes you saw above, but this time the page will look like this:

    As the last change for the Hello World example, modify the code to include HTML comments around the code of the scripts tags (but inside the <script> tags) so it looks like this:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Hello World</title>
    <script language="JavaScript" type="text/javascript">
    <!-- hiding Javascript from old browsers
    window.alert("Hello World, from the head element");
    // end of the HTML comment -->
    </script>
    </head>
    <body>
    <script language="JavaScript" type="text/javascript">
    <!-- hiding Javascript from old browsers
    window.alert("Hello World, from the body element");
    // end of the HTML comment -->
    </script>
    <h1>
    <script language="JavaScript" type="text/javascript">
    <!-- hiding Javascript from old browsers
    document.write("Hello Javascript");
    // end of the HTML comment -->
    </script>
    </h1>
    </body>
    </html>

    Reload the Web page again and you will get the same message boxes and the same <h1> Hello Javascript element.

    More JavaScript Articles
    More By Michael Youssef


     

    JAVASCRIPT ARTICLES

    - Comparing Fields and Customizing Error Messa...
    - Checking Numbers and File Extensions with jQ...
    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek