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
- Apply expert script debugging and design tips
- Get ongoing support at IDG Books Worldwide and Danny Goodman's Web sites
Read an Excerpt
Chapter 4: Browser and Document Objects
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.
Interactive user interfaces
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
and post it to your social network
Most Helpful Customer Reviews
See all customer reviews >