Thursday, 7 December 2017

Powerful Applications with JavaScript

Java can be used to create very powerful applications. JavaScript scripts cannot really do all the neat things that Java applets can.
On the other hand, it is much more difficult to write programs in Java than it is to write scripts in JavaScript.

The power of cookies is that they offer persistence. When the document that created or modified a cookie is no longer loaded, the data in the cookie is still there.
Other documents that know about the cookie can access and modify its data, so the data can be shared between documents.

Through the use of a feature called a cookie, documents can share information with each other.
Cookies are small data objects that reside on the user's machine. You can write JavaScript code to create, modify, and delete cookies.
Using the ability to write frame contents on the fly, you can also use cookies to remember things about the user and to tailor the contents of your document's frames to that user.
An example might be an a personalized greeting, combined with an indication of how long it has been since the user last loaded the document.

The user of an online catalog could select items from several pages. Each page could record the user's selection in a cookie. When the user was finally ready to send in the order, the cookie would be read back into a form for the user to verify.
The entire list, containing items from several different documents, would then be submitted to the store.

One potential use for cookies is in online catalogs. A store with an extensive inventory would not want to put its entire catalog in a single document.
Instead, they would probably break up the catalog into manageable pieces, with each separate document focusing on a particular class of merchandise.

In addition to form and field event handlers, you can write event handlers to be executed when the pointing device moves over certain element; such an event is called a mouseover event.
You can also define event handlers that are executed when the document is loaded and when the document is exited.

Within the submit event handler, you can do whatever you like. Most of the input field contents are accessible to your JavaScript code.
You can modify the data and you can decide not to send it out at all. You can create a document and display it in another frame or window. And you can still send it to a CGI process.

Within the FORM element, another kind of event, the submit event, occurs when the user clicks on a submit button. Before there was JavaScript, clicking on the submit button sent the form data to a CGI process on a remote server.
The CGI process would then process the data and send back a new page of data. With JavaScript, you can write an event handler for the submit event.

Within a FORM element, there are SELECT, INPUT, and TEXTAREA elements, which act as input fields. The user can typically move the cursor from one input field to another by using the Tab key or by clicking the pointing device in an input field.
When the user moves the cursor from one field to another

When the user moves the cursor from one field to another the destination field is said to have acquired focus; the user can now modify that field's contents.

JavaScript recognizes several events that a user can cause within a document.
You can create JavaScript code that reacts to those events, providing interaction with the user.

You can write a JavaScript code that can rewrite the contents of a frame in response to the user's actions.

You can't modify a frame's contents, but you can rewrite the frame contents from scratch.
FRAME elements are contained within FRAMESET elements, and FRAMESET elements can also contain other FRAMESET elements, allowing you to divide and subdivide the browser window.
Be careful with this capability, however: You can easily subdivide the browser window to the point that nothing of value is visible.

 You define frames within a frame document, or layout document. A typical Web page is made up of an HTML element that contains a HEAD element and a BODY element.
A frame document is usually made up of an HTML element that contains a HEAD element and a FRAMESET element.

JavaScript code in the document of one frame can clear another frame and write new HTML or even more JavaScript code into another frame.
Before JavaScript, it was enormously complicated to create, on the fly, a new page tailored to the user's wishes. Now you can do it yourself.

Frames give you more control over the layout of your document than conventional HTML allows, and frames let you keep parts of your documents on the screen while other parts change. For example, in one frame you can place a corporate logo, copyright information, and so forth; in another frame, you can place a document describing some particularly interesting information about your company.
As the user pages through your Web site, the frame that holds your logo and copyright can remain visible while the information in the other frame changes.
You can create documents that split the browser window into pieces-you have probably seen such documents while surfing the Web.

The pieces are called frames, and much of JavaScript's power derives from what it can do with frames.