JavaScript
  Home arrow JavaScript arrow Page 2 - Some Simple JavaScript Functions
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

Some Simple JavaScript Functions
By: Annette Tennison
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 29
    2002-01-31

    Table of Contents:
  • Some Simple JavaScript Functions
  • JavaScript functions
  • JavaScript functions (contd.)
  • Conclusion

  • 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


    Some Simple JavaScript Functions - JavaScript functions


    (Page 2 of 4 )

    Before we can implement the functions i'm about to describe, we need to know how to setup our web page so that it can run the JavaScript. JavaScript code is inserted between opening and closing script tags: <script> and </script>, like this:

    <script language="JavaScript">

    // JavaScript code goes here

    </script>


    These script tags can be placed anywhere on the page, however it's common practice to place them between the <head> and </head> tags. A basic HTML page that contains some JavaScript looks like this:

    <html>

    <head>

    <title> My Test Page </title>

    <script language="JavaScript">

    function testfunc()

    {

    var x = 1;

    }

    </script>

    </head>

    <body>

    <h1>Hello</h1>

    </body>

    </html>


    For the examples in this article, you should use the basic document format I have just shown you, inserting the JavaScript code between the <script> and </script> tags. When you load the page in your browser, the JavaScript code will be executed automatically.

    Displaying the browsers name and version number

    The "navigator" object in JavaScript contains the details of the users browser, including its name and version number. We can display them in our browser using the document.write function:

    document.write("Your browser is: " + navigator.appName);

    document.write("<br>Its version is: " + navigator.appVersion);


    I run Windows 2000, Internet Explorer version 5.5 and HotBar, so the output from the code above looks like this in my browser window:

    The output in my browser window

    Changing the text in the status bar of the browser

    To change the text in the status bar of a browser window, we just change the "status" member of the "window" object, which represents our entire browser window:

    window.status = "This is some text";

    Take a look at the status text of my browser window after I added the line of code above into my HTML page:

    The status text in my browser window

    More JavaScript Articles
    More By Annette Tennison


     

    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