Web Hosting Offers
See the new scripts recently added to Dynamic Drive. Click here.
Original, practical CSS codes and examples such as CSS menus for your site.
javascript tutorial Browse Advanced JavaScript Tutorial
Browse JavaScript Script resources
Browse JavaScript FAQS
JavaScript Tutorial: Browse
javascript tutorial
Buy templates
Home >> Tutorials >> Basic Javascript Tutorials

Javascript Introduction:
 
What is javascriptEmbedding JS into HTMLSpecifying JS version
Specifying fileHiding script 

What is Javascript?
JavaScript is an object-oriented scripting language developed by Netscape that allows you to create web pages. Javascript is a client-side scripting language. This means the user's browser will be running the script. This is opposite to client-side is server-side, which occurs in a language like PHP. These PHP scripts are run by the web hosting server.

JavaScript is not Java.

JavaScript and Java are similar in some ways but fundamentally different in others. Java is a compiled programming language, similar to languages like C, C++, or Pascal.

JavaScript is a scripting language, meant  for small programs used only from within web browsers. A JavaScript script can't run alone, without the browser, the way a Java program does. JScript is Microsoft's version of JavaScript.

Top




Embedding JavaScript into a HTML-page

JavaScript code is embedded directly into a HTML-page using <script>  and </script> tags. It is possible to  embed  many scripts into a single document , using multiple SCRIPT tags.

A typical format for a javascript embedded into a HTML file would look like :
<script ="JavaScript">

<!--

Javascript statements
.
.
//-->

</script>

JavaScript is case sensitive:
Unlike HTML, Javascript is case-sensitive.

Top




Specifying the JavaScript Version

As mentioned above, there are several versions of JavaScript supported by certain browsers and browser  versions. You can specify the javascript version using  the LANGUAGE attribute.
Eg:

<script language ="JavaScript1.1">

<!--

  Javascript statements
//-->

</script>

Statements within a <SCRIPT> tag are ignored if the browser does not support the javascript version specified in the LANGUAGE attribute. In other words, you can specify that a section of  code only be executed by browsers which support a particular version of JavaScript.

Eg:

    1)Navigator 2.0 executes code within the <SCRIPT LANGUAGE="JavaScript"> tag; it ignores
     code within the <SCRIPT LANGUAGE="JavaScript1.1"> and <SCRIPT

     LANGUAGE="JavaScript1.2"> tags.

    2) Navigator 3.0 executes code within the <SCRIPT LANGUAGE="JavaScript"> and <SCRIPT

     LANGUAGE="JavaScript1.1"> tags; it ignores code within the <SCRIPT

     LANGUAGE="JavaScript1.2"> tag.

    3) Navigator 4.0 executes code within the <SCRIPT LANGUAGE="JavaScript">, <SCRIPT

     LANGUAGE="JavaScript1.1">, and <SCRIPT LANGUAGE="JavaScript1.2">

Top




Specifying a file for Javascript Code

You can include an external file containing JavaScript code into a HTML file. SRC, another attribute of the SCRIPT  tag is used for this purpose.  This feature is helpful when you want to hide your javascript code from others (HTML Source code of all web pages can be seen from the borwser. Using this feature you can hide your javascript code from others)

For example: You can have all your javascript statements in a file called 'myjavascript.js' and can include into your HTML file as shown below:

<HEAD>
<TITLE>My Javascript Page</TITLE>

<SCRIPT SRC="myjavascript.js">

</SCRIPT>

</HEAD>

<BODY>

HTML Code

.

.

.

<BODY>

The external file is simply a text file containing only JavaScript statements and function definitions  and filename ends with  the extension ".js". The SRC attribute can specify any URL, relative or absolute. All JavaScript statements within a <SCRIPT> tag with a SRC attribute are ignored (unless there was an error in file inclusion).

Top




Hiding Scripts within Comment Tags

Only Netscape Navigator versions 2.0 and later recognize JavaScript. If a browser does not recognize javascript code, the whole code in displayed when you see the HTML document. To ensure that your JavaScript code is not displayed by old browsers, place Javascript inside comment fields. The markup to begin a comment  field is <!-- while you close a comment field using  //-->.

Eg:
<SCRIPT>

<!-- Hide script contents from old browsers that does not javascript.

Include JavaScript statements...

// Finish hiding here. -->

</SCRIPT>

Top


About Focus on JavaScript
Focus on JavaScript

JavaScript and Emails
19 Aug 2008 at 3:02am
Email programs are very different to Web Browsers regarding JavaScript. One format that most email programs support to send emails in is HTML. Just because you can use HTML in emails...
Latitude and Longitude
18 Aug 2008 at 4:49am
Google Maps can display any location based on its latitude and longitude The easiest way to specify what part of our planet that you want your Google map to display is...
Cross Field Validation
17 Aug 2008 at 12:42pm
Sometimes the valid values for one form field depend on the value of another field In the last (for now) JavaScript tutorial on form field validation we consider the need to...
Site Navigation
16 Aug 2008 at 9:28am
JavaScript allows you to use a drop down list for site navigation If you have lots of pages on your web site then providing a plain list of links will take...
Display Author Time
15 Aug 2008 at 9:34am
JavaScript can tell the time at different places Let your visitors know what time it is where you are with this JavaScript. As long as your visitor's have their local time...
Expanding and Shrinking Text Banner
14 Aug 2008 at 9:31am
Animate text with JavaScript Create an attention grabbing text banner on your page by having the text expand and then shrink to be replaced by the next line of text. Expanding and...
appendChild
13 Aug 2008 at 6:21am
JavaScript can easily add new content to an existing web page. In the tenth Document Object Model tutorial we looked at how to create new elements for our web page but...
"Dojo: The Definitive Guide"
12 Aug 2008 at 3:12am
Even bad products can have good books written about them There are mediocre JavaScript libraries and there are some really bad ones as well and each has its followers who disregard...
"Object-Oriented JavaScript"
11 Aug 2008 at 2:26am
A book that demonstrates some of what JavaScript can really do. There are lots of books around that introduce beginners to JavaScript as well as quite a few that show you...
Validate on Submit
10 Aug 2008 at 12:44pm
Your visitor may not access all the fields in the form so validating each field individually is not enough. As well as validating individual fields in a form you should also...

Page contents: itechies.net - javascript introduction
javascript tutorial
javascript book
Buy this book