Javascript Bible, Third Edition with CD Rom

Javascript Bible, Third Edition with CD Rom

3.2 9
by Danny Goodman
     
 

Create Web Pages That Think! Whether you're a novice Web author wondering what JavaScript can do for you or a seasoned HTML scripter anxious to exploit JavaScript's evolving functionality, this authoritative, all-in-one resource -- by the most experienced computer scripting author in the industry -- lets you create pages so inviting, users will spend more time at your… See more details below

Overview

Create Web Pages That Think! Whether you're a novice Web author wondering what JavaScript can do for you or a seasoned HTML scripter anxious to exploit JavaScript's evolving functionality, this authoritative, all-in-one resource -- by the most experienced computer scripting author in the industry -- lets you create pages so inviting, users will spend more time at your Web site and come back for more!

For Cool Web Pages, Master Today's Hottest Scripting Language!

  • Get up to speed FAST with "crash courses" on programming fundamentals and object-oriented basics
  • Key into the lessons you need with clearly labeled beginning, intermediate, and advanced terminology
  • Implement JavaScript into your site with step-by-step how-to's
  • Learn from ready-to-run JavaScript and HTML examples
  • Apply expert script debugging and design tips
  • Get ongoing support at IDG Books Worldwide and Danny Goodman's Web sites

Editorial Reviews

Booknews
The author covers the basics of document objects and forms, control structures, functions, operators, Java applets, the differences between Netscape and Microsoft's implementations of JavaScript, cross- browser dynamic HTML applications, and debugging tools. Includes beginning and advanced tutorials, and appends answers to the tutorial exercises as well as a list of JavaScript Internet resources. The CD- ROM contains the complete JavaScript for the examples in the book and seven additional chapters with working applications, including calendars, forms, graphics, intelligent flags, and a decision helper. Annotation c. by Book News, Inc., Portland, Or.

Product Details

ISBN-13:
9780764531880
Publisher:
Wiley
Publication date:
03/16/1998
Series:
Bible Series
Edition description:
Older Edition
Pages:
1056
Product dimensions:
7.40(w) x 9.27(h) x 1.94(d)

Read an Excerpt


Chapter 4: Browser and Document Objects

This chapter marks the first of nine tutorial chapters (which compose Part 11) tailored to authors who have at least basic grounding in HTML concepts. You will see several practical applications of JavaScript and begin to see how a JavaScript-enabled browser turns familiar HTML elements into objects that your scripts control.

Scripts Run the Show

If you have authored in plain HTML, you are familiar with how HTML tags influence the way content is rendered on a page when viewed in the browser. As the page loads, the browser recognizes tags (by virtue of their containing angle brackets) as formatting instructions. Instructions are read from the top of the document downward, and elements defined in the HTML document appear on screen in the same order in which they are entered in the document. As an author, you do a little work one time up front - adding the tags - and the browser does a lot more work every time a visitor loads the page into a browser.

Assume for a moment that one of the elements on the page is a text field inside a form. The user is supposed to enter some text in the text field and then click the Submit button to send that information back to the Web server. If that information must be an Internet e-mail address, how do you ensure the user included the "@" symbol in the address?

One way is to have a Common Gateway Interface (CGI) program on the server scan the submitted form data after the user has clicked the Submit button and the form information has been transferred to the server. If the user omitted or forgot the "@" symbol, the CGI program resends the page, but this time with an instruction to include the symbol in the address. Nothing is wrong with this exchange, but it means a significant delay for the user to find out that the address does not contain the crucial symbol. Moreover, the Web server has has been transferred to the server. If the user omitted or forgot the "@" symbol, the CGI program resends the page, but this time with an instruction to include the symbol in the address. Nothing is wrong with this exchange, but it means a significant delay for the user to find out that the address does not contain the crucial symbol. Moreover, the Web server has had to expend some of its resources to perform the validation and communicate back to the visitor. If the Web site is a busy vile, the server may stop, trying to perform hundreds of these validations at any given moment, probably slowing response time to the user even more.

Now imagine if the document containing that text field had some intelligence built into it that could make sure the text field entry contains the IV symbol before ever sending one bit (literally) of data to the server. That kind of intelligence would have to be embedded in the document in some fashion downloaded with the page's content so it can stand ready to jump into action when called upon. The browser must know how to run that embedded program Some user action must start the program, perhaps when the user clicks the Start button. As the program runs, if it detects a lack of the "( )" symbol, an alert message should appear to bring the problem to the, user's attention.

This kind of presubmissiondata entry validation is but one of the practical many. JavaScript adds intelligence to an HTML document.. leaving as this as an example, you might recognize that a script must know how to look into what has been typed text field; a script must also know hopw to let a submission continue or how to abort the submission. A browser capable of running JavaScript programs conveniently treats elements such as the text field as 6hpms. A JavaScript script controls the action and behavior of objects - most of which you see in the browser window.

JavaScript in Action

By adding lines of JavaScript code, to your HTML documents, you control on screen objects as your applications requires. To give you an idea of the scope of application you can create with JavaScript, I show you several applications from the CD- ROM (in the folder named Bonus Applications)- I strongly urge you open the applications and play with them in your browser- Links to the application files from the CD-ROM can be found on the page tutor.htm in the listings folder. I also provide URLs to the examples at my Web site.

Interactive user interfaces

HTML hyperlinks do a fine job, but they're not necessarily the most engaging way to present a table of contents to a large site or document. With a bit of JavaScript, it is possible to create an interact've and expandable table of contents listing that displays the hierarchy of a large body of material (see Figure 4-1).

Click on a gray widget icon to expand the items underneath. An endpoint item has an orange and black widget icon. Items in the outline can be links to other pages or descriptive information. You also maintain the same kind of font control over each entry as you would expect from HTML. While such outlines have been created with server CGIs in the past, the response time between clicks is terribly slow. By placing all of the smarts behind the outline inside the page, it downloads once and runs quickly after each click.

As demonstrated in the detailed description of this outline in the application Outline- Style Table of Contents (Chapter 50 of the bonus applications chapters on the CD- ROM), the scriptable workings can be implemented within straight HTML for Navigator 2 and 3 and in Dynamic HTML for Navigator 4 and Internet Explorer 4. Either way you do it, the quick response and action on the screen makes for a more engaging experience for Web surfers who are in a hurry to scout your site.

Small data lookup

A common application on the Web is having a CGI program present a page that visitors use to access large databases on the server. Large data collections are best left on the server, where search engines and other technologies are the best fit. But If your page acts as a "front end" to a small data collection lookup, you can consider embedding that data collection in the document (out of view) and letting JavaScript act as the intermediary between user and data.

I've done just that in a Social Security prefix lookup system shown in Figure 4-2. 1 converted a printed table of about 55 entries into a JavaScript table that occupies only a few hundred bytes. When the visitor types the three-character prefix of his or her Social Security number into the field and clicks the Search button, a script...

Read More

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >