You are here: Web Design > JavaScript DinkostaOnline 
  

Home
Topics
Computers
Web design
Software
JavaScript
 JavaScript is a scripting language used to create interactive web pages. Though less powerful than Java, it is also much simpler to learn. This language was created in 1995 and is unavoidable on the Internet today. Almost every web site on the Net today has in its code JavaScript. They use the language for different purposes: to give to the page interactivity, to check if a form is properly filled out etc, but there are some web sites that use JavaScript to annoy you with pop-up windows, to redirect you to pages where you don't want to go and so on.
 It is one of the easier languages to learn, at least easier than languages like Java and C++, but more complex than HTML. In order to learn JavaScript, you need first to understand HTML. To master JavaScript and to be able to write your own scripts, you will need to buy a good book about JavaScript. My recommendation would be the book "JavaScript Bible" by Danny Goodman or "JavaScript" by David Flanagan.
JavaScript is a simple to comprehend, easy to use, general purpose scripting language. When used in conjunction with a Web browser's Document Object Model (DOM), it can produce powerful dynamic HTML browser-based applications which also can feature animation and sound.
 On the next few pages you can find examples for window manipulation, no right-click, hide and display content, add to favorites, convertors, image-rollovers and reflected image, animation, date and time, dynamic content, calculators and hotkeys and so on. All the script examples are tested with Internet Explorer 6, and work on all IE 4+ browsers (unless stated otherwise). Most of the scripts should also work with other browsers.

 The document 


JavaScript Basics

 JavaScript code is made up of statements which serve to make assignments, compare values, and execute other sections of code. Below you can see the main elements of the JavaScript grammar.

Variables
They are used to store changeable values. Variable names must not contain reserved key words or spaces. If you need more than one word for the variable name, use 'underscore' (_) or the 'interCap' format (examples: var the_name or var theName).
Example: var total=50.

Operators
Actors which can be used to calculate or compare values. Some of the JavaScript operators are: +, =, -, *, = =, !=, >, <=, &&, || .
Example: Two values may be summed using the addition operator (+); total+tax
Example: Two values may be compared using the greater-than operator (>); total>200

Expressions
Any combination of variables, operators, and statements which evaluate to some result. In English this might be termed a "sentence" or even a "phrase", in that grammatical elements are combined into a cogent meaning.
Example: total=100;
Example: if (total>100)

Statements
As in English, a statement pulls all grammatical elements together into a full thought. JavaScript statements may take the form of conditionals, loops, or object manipulations. It is good form to separate statements by semicolons, although this is only mandatory if multiple statements reside on the same line.
Example: if (total>100) {statements;} else {statements;}
Example: while (clicks<10) {statements;}

Objects
Containing constructs which possess a set of values, each value reflected into an individual property of that object. Objects are a critical concept and feature of JavaScript. A single object may contain many properties, each property which acts like a variable reflecting a certain value. JavaScript can reference a large number of "built-in" objects which refer to characteristics of a Web document. For instance, the document object contains properties which reflect the background color of the current document, its title, and many more.

Functions and Methods
A function is a discrete set of statements which perform some action. It may accept incoming values (parameters), and it may return an outgoing value. A function is "called" from a JavaScript statement to perform its duty. A method is simply a function which is contained in an object. For instance, a function which closes the current window, named close(), is part of the window object; thus, window.close() is known as a method.

 

The DOM

DOM stands for Document Object Model, and allows programmers generic access - adding, deleting, and manipulating - of all styles, attributes, and elements in a document. It can be accessed via any language available in the browser, including Java, JavaScript/ECMAScript/JScript, and VBScript (MSIE only). Every tag, attribute, style, and piece of text is available to be accessed and manipulated via the DOM.
On the top of the DOM hierarchy is the window and that is actually the browser window where the page is displayed. Some of the methods are: alert(), prompt(), confirm(), open(), close() etc, and his most important properties are window.status and location.
Next in this hierarchy is the document. This part of the DOM is of the most interest for scripting. Interesting properties here for scripting are: bgColor, fgColor, cookies, forms, images etc.
Some of the other objects in the DOM hierarchy are: form, image, text, button, select, submit etc.
In order to tell JavaScript what to do with an element, you need to tell JavaScript where to look for that element (reference). For example, to reference a 'button' object, named 'first', inside a form called 'test', you will need to write: window.document.test.first (it is very helpful for referencing if you name the objects).


HTML  |  JavaScript  |  Windows tips  |  The Registry  |  Software  |  Batch files
Hosted by www.Geocities.ws

1