Javascript Introduction:
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
Loan Repayment Calculator
3 Sep 2010 at 3:06am
Allow your visitors to calculate how much the repayments on their loan will be by adding this loan repayment calculator to your site. They simply enter the loan amount, interest rate, term, and repayment frequency and the repayment amount will be calculated for them.
Loan Repayment Calculator
Loan Repayment Calculator originally appeared on About.com Focus on JavaScript on Friday, September 3rd, 2010 at 08:06:16.
Permalink | Comment | Email this
Table Generator
2 Sep 2010 at 12:03am
How many times have you tried to code a table and then found that your web page is totally stuffed up in one or more browsers because you left out a tag? This JavaScript driven table generator will solve this problem for you by creating all of the necessary tags for you for whatever sized table that you choose. It will even create some basic stylesheet entries for you to get you started on defining the table's appearance.
Table Generator
Table Generator originally appeared on About.com Focus on JavaScript on Thursday, September 2nd, 2010 at 05:03:59.
Permalink | Comment | Email this
Multiple Requests
1 Sep 2010 at 10:22am
In all of the preceding Ajax tutorials we have looked at how to use Ajax to make a single request to the server. Because we are making asynchronous requests there is nothing to stop us from sending multiple requests back to the server to retrieve different things all at the same time. In this thirteenth Ajax tutorial we look at how we can set up multiple requests that can work independently of one another.
Multiple Requests
Multiple Requests originally appeared on About.com Focus on JavaScript on Wednesday, September 1st, 2010 at 15:22:55.
Permalink | Comment | Email this
Toggle Action
31 Aug 2010 at 7:20am
Web pages are usually stateless - meaning that when someone visits a web page the page behaves the same regardless of what they did before. To allow a web page to behave differently based on what has gone on before you need a way to save information about what has come before. The way to do this is to store a cookie on your visitor's computer that contains information about the past state of the page (or site) and then retrieve that information to determine what to do next. In this example we look at how to get a web page to toggle between two actions based on whether your visitor has come to the page an odd or an even number of times.
Toggle Action
Toggle Action originally appeared on About.com Focus on JavaScript on Tuesday, August 31st, 2010 at 12:20:05.
Permalink | Comment | Email this
Event Modifiers
30 Aug 2010 at 2:17am
It is possible to use keys on the keyboard to change what clicking a mouse button does. There are only a few keys on the keyboard that can be used to do it easily though.
Event Modifiers
Event Modifiers originally appeared on About.com Focus on JavaScript on Monday, August 30th, 2010 at 07:17:13.
Permalink | Comment | Email this
Functions and Methods
29 Aug 2010 at 11:42am
In JavaScript all functions are methods. The difference between a function and a method in JavaScript is mostly a matter of terminology. If you are using a procedural approach you will call them functions and if you are using an object oriented approach then you'll call them methods. While functions and methods are actually different from one another, in JavaScript there is no real distinction because all stand alone functions are really methods of the window object. In this eight "Learn Modern JavaScript" tutorial we look at the main ways to define a function or method.
Functions and Methods
Functions and Methods originally appeared on About.com Focus on JavaScript on Sunday, August 29th, 2010 at 16:42:12.
Permalink | Comment | Email this
Asking for Help
28 Aug 2010 at 8:50am
Everyone will at least occasionally strike problems with JavaScript code that they can't solve themselves. Fortunately there are plenty of people out there who are prepared to provide help. It just comes down to where you ask and how you ask as to whether you will get the needed help.
Asking for Help
Asking for Help originally appeared on About.com Focus on JavaScript on Saturday, August 28th, 2010 at 13:50:38.
Permalink | Comment | Email this
Common JavaScript Errors
27 Aug 2010 at 6:07am
Everyone makes mistakes, particularly when writing a new program. What you have to do with your program is to locate those errors and correct them so that the program will do what it is supposed to do. A good place to start when checking for errors is to see if you have made any of the common errors that just about everyone makes from time to time when writing JavaScript programs. If you can locate and correct these nine common types of error then you will be a good part of the way to getting your program to work correctly.
Common JavaScript Errors
Common JavaScript Errors originally appeared on About.com Focus on JavaScript on Friday, August 27th, 2010 at 11:07:24.
Permalink | Comment | Email this
Two DOMs
26 Aug 2010 at 4:59am
The Document Object Model that JavaScript uses to access an HTML web page is not identical to the one it needs to use to access XHTML. Switching from using HTML to using XHTML will mean minor changes to your (X)HTML code and much more significant changes to the JavaScript. How easy or difficult the JavaScript will be to convert will depend on just how you are accessing the HTML from the JavaScript in the first place.
Two DOMs
Two DOMs originally appeared on About.com Focus on JavaScript on Thursday, August 26th, 2010 at 09:59:52.
Permalink | Comment | Email this
Aborting Ajax
25 Aug 2010 at 10:52am
Since Ajax is normally run asynchronously where we don't wait for the response to come back, circumstances may change so that the response is no longer required and we want to abort the request in order to make another more relevant one. In this twelfth Ajax tutorial we look at how to abort an outstanding Ajax request so that the browser can initiate a replacement request using the same code without getting confused between the original and replacement responses.
Aborting Ajax
Aborting Ajax originally appeared on About.com Focus on JavaScript on Wednesday, August 25th, 2010 at 15:52:02.
Permalink | Comment | Email this