Miscellaneous

  Home arrow Miscellaneous arrow Introduction to Java Script
MISCELLANEOUS

Introduction to Java Script
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2004-02-08

    Table of Contents:
  • Introduction to Java Script
  • Variables
  • Prompts
  • If -Then Statements

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Introduction to Java Script


    (Page 1 of 4 )

    Many times when you are building a web page you might need more than just PHP and HTML. Java Script can fill that gap. In this tutorial, John Johnston will get you started with Java Script.

    By : John Johnston

    Java Script, not the same thing as Java which is an entirely different language and used for very different reasons, is a web based scripting (programming ) language developed by Netscape and is used to add interactivity to web pages. While it can be simple to use, like all programming languages, JavaScript follows strict syntax rules that you cannot break. If you don’t follow the syntax, it will not work.

    How Does Java Script Work?

    Java Script works by telling your browser that (1) it is a language on your browser, and (2) what to do with the scripts that you write. This is of course, over simplified, but we are not developers of languages, nor senior programmers, so we aren’t going to concern ourselves with how this all works. What we will consider is how to make it work and which browsers will and won’t use Java Script.

    Does Java Script Work on all Browsers?

    Unfortunately, no. While most versions of Netscape and Internet Explorer will work ( from version 3 on for both ), some browsers simply don’t understand Java Script and as such, we are required to hide these scripts from those browsers so that people don’t hunt us down and complain. To make things even more complicated, not all browsers handle JavaScript in the same manner. While the end result is the same, how the browser does it may be entirely different, even in the same version of a browser! Scared? Don’t be. Java Script can be the simpelist and easiest way to handle all your web based programming needs.

    Now some of you might ask about those browsers that don’t handle JavaScript. In essence, these browsers would just spit out all the scripting you have done as text in your HTML page. This would confuse everyone. Luckily, HTML has a built in way to comment, or hide, these things. In this way, we can hide our Script from browsers that cannot read it, and still let the browsers that can use it! How? Take a look below.

    <html>
    <head>
    <title> Title of your page </title>
    <script language="JavaScript">
    <!-- hide this stuff from other browsers
    YOUR SCRIPT HERE
    // end the hiding comment -->
    </script>
    </head>

    You should notice several things right off the bat. First, we have to tell our browser that we are using Java Script. ( <script language="JavaScript">). While Java Script is the default scripting language for browsers, this might not always be the case, and it is a good idea to keep it in there. The next thing that you should notice is that we have hidden our script from the browsers that can’t handle it with ( <!-- something //-->). The third thing that you should notice is that this script is placed entirely within the head of the HTML document. Most of your scripting will happen here. While you can, and will, use JavaScript in the body of your document, all of the really important programming will occur in the head. Finally, you should notice that just like basic HTML, you must open and close your script tags.

    A Note on Programming

    Some of the most important things about programming are not necessarily its function, but rather it’s format. Just like writing a research paper, the greatest paper in the world will do you no good if other people can’t read and understand it. Programming is no different. Form and style do count. The single easiest way to make sure that people understand what you are doing and why is to comment out areas of your script. This acts as a simple way to note things in your script so that it is easy to understand for those who want to steal your scripts…or for scripts that you want to steal yourself! To comment out a section just follow the format below.

    /* this is
    a huge block
    of text that I've
    commented out */

    Anything placed between the /* blah blah blah */ will be ignored by both HTML and JavaScript. With that let’s start some scripting!

    More Miscellaneous Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap