JavaScript - An Overview

In the early days of the Web, we had static HTML pages. However as days went by, dynamism in Web pages stated to pour in. We can nowadays get some sort of dynamism using CGI on the server side. Programming languages and scripting languages satisfying CGI can generate dynamic Web pages on the basis of user information being supplied in using forms. However this step involves a time lag, as a request needs to be sent to the server, an application needs to be executed, and the results need to be interpreted by the browser before they are displayed. This issue gave birth to client-side scripting languages, that is, scripts or executables that could be part of the HTML page and could notify the page based on certain events like mouse clicks, key presses, or text selections.

Netscape introduced JavaScript, which is a cross-platform, object-based scripting language. It can be used for creating both server-side and client-side applications. But mainly it is being used on client-side applications. It allows us to create new windows or modify existing windows. But the most important benefit of Javascript is client-side validation of FROM data. If we have a form in which we want users to fill in all the fields, we need a mechanism for error checking, such as whether social security number field in the form has been filled with numbers or there is any field which is not filled by the users etc. There are a number of such things to be checked before sending these information to the back-end. By having such a client side mechanism, it is easier for detecting and correcting the errors instantaneously. Javascript has been designed with these goals in mind and Javascript is quite good at solving these issues on client side processing.

Different components of HTML page including elements belonging to a form are represented as objects that can be accessed by Javascript. These objects are organized in a hierarchy that begins at the top with the window object. A window represents a browser window or frame. Objects have properties and methods associated with them, and the properties may actually be references to other objects contained in an object. A window has several properties such as frames and a history property containing information about the URLs that the client has visited within this window. Other properties contain information about the window itself, for example, its height and width.

Objects may also have methods associated with them, For instance, a window object has an alert method that can be used for throwing an Alert dialog box, a moveTo method that allows you to move the window, a resizeTo() method that allows us to change the size of the window, and so on. Objects can also have events with associated event handlers. In the case of a window, therefore, when the window is loaded, a load event occurs, which can be bundled by a well-defined function. The "onLoad" event handler is used to specify the function that will handle this. Similarly we can supply our own functions to handle events like unload, window move, resize etc. Thus Javascript is a flexible and object-based language.