Home > Store

Essential JavaScript for Web Professionals

Register your product to gain access to bonus material or receive a coupon.

Essential JavaScript for Web Professionals

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 1999
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-013056-7
  • ISBN-13: 978-0-13-013056-3


1305F-7

With JavaScript, you can build sites that look hotter and work smarter than ever before! Now, learn JavaScript by example, from two leading Fortune 500 Web developers! You'll learn all you need to get results as you build real-world practice sites that sell products, educate visitors, offer subscriptions, and display ads. Best of all, the finished sites are on the Web—so you can reuse the code and see exactly how your pages should look and work!

Write JavaScript to do all this, and much more!

  • Detect browsers and platforms
  • Create content dynamically
  • Create image rollovers
  • Enhance navigation
  • Provide error handling
  • Generate windows
  • Communicate between frames Rely on Essential Guides for ALL the Web Skills You Need!

All these books share the same great format, and the same dynamic website. . .

so once you've used one, they're all a piece of cake!

  • Essential CSS & DHTML for Web Professionals
  • Essential PERL 5 for Web Professionals
  • Essential Photoshop 5 for Web Professionals
  • Essential JavaScript for Web Professionals
  • With more to come!

Sample Content

Downloadable Sample Chapter

Click here for a sample chapter for this book: 0130130567.pdf

Table of Contents



1. Dynamism and Detection.

Project I: Generating Platform-Specific Content. Inserting a Script into Your HTML. JavaScript Hierarchies. Platform/Browser Detection. Creating Dynamic HTML from within JavaScript. Project II: Printing Copyright Information and Last-Modified Date. Introduction of the Last-Modified Property. Dynamically Printing Nonstring Data.



2. Image Rollovers.

Project I: Rollover Script. Creating the IMAGE Objects. Image Rollover Functions. Inserting the Event Handlers. Project II: Adding Advanced Functionality to Our Rollovers. Inserting the Event Handlers. Creating the IMAGE Objects. Inserting the Rollover Functions. Rollover Quirks.



3. JavaScript for Navigation.

Project I: JavaScript and Pull-Down Menus. Creating the Navigation Function. Inserting the Event Handler. Using on Change for Instant Gratification. Project II: Using Multiple Pull-Down Menus for Navigation. Creating the Arrays. Creating the Drill-Down Menu Function. Creating the Navigation Function. Inserting the Event Handlers. Project III: Using JavaScript on a Log-in Page. Inserting the Event Handler.



4. Error Handling in Forms.

Project I: Checking for Empty Form Fields. Checking Forms for Empty Text Box Fields. Making Sure a Pull-Down Menu Option Was Chosen. Project II: Checking for Erroneous Data in Form Fields. Checking E-mail Addresses for Valid Characters. Checking for Area Codes in Phone Numbers. Making Sure Zip Codes Have Only Numbers. Project III: Letting the User Know What's Wrong.



5. JavaScript Windows and Frames.

A Look at the WINDOW Object. Project I: Creating, Populating, and Closing Windows. Creating and Defining the Arrays. Creating the Function. Inserting the Event Handlers. Project II: Using JavaScript to Talk between Frames. Figuring Out Your Frame Hierarchy. Creating a Function to Check Which Section You're In. Inserting the Event Handler.



6. Advanced JavaScript.

Project I: Create Submenus for the Stitch Secondary Pages. Functional Specification. Creating and Populating the Arrays to Store Data. Creating the Functions to Run the Submenu System. Inserting the Event Handlers.



Appendix A: Event Handlers.


Appendix B: JavaScript Objects.


Index.

Preface

Introduction

Welcome! This book is something we wish we had when we were first starting out with JavaScript. At that time, there were basically two types of instructional books on the market: 1200-page tomes of seemingly arcane knowledge, and books that were overly simplified and lacking in practical information. Unfortunately, there were no books that were informative and at the same time provided instruction that could be used quickly and effectively in real-world situations.

This book will guide you through JavaScript using examples taken straight from situations that are faced every day during Web site construction. It starts off with simple examples and becomes quite sophisticated with the scripting toward the end of the book. With that said, let's look a little more closely at how this book is laid out and a brief summary of scripting, as well as what JavaScript can and can't do for you.


How This Book Is Laid Out

Chances are that at least some of you picked up this book when your boss called you into his or her office and showed you a Web site that made use of JavaScript. You were then told in no uncertain terms that it was your job to implement the same, or similar, feature on your Web site. "No problem," you respond, while saying to yourself, "I better learnJavaScript and fast!"

This is often how we expand our skills: We are given a job, and if we don't know exactly how to do it, we quickly learn how. In keeping with this real-world model, this book is split into two main projects. For each of the main projects, we will be responsible for creating and/or upgrading the Web site for a fictitious company.

For the first three chapters, we will revamp the homepage for Shelley Biotechnologies, a fast-growing bio-tech startup. In each chapter we have at least one project that consists of commonly used JavaScript solutions that range from easy to moderately difficult. At the end of each chapter there are more advanced exercises that you can complete on your own to expand your skills. In the second half of the book we will make some much-needed additions to Stitch Magazine's Web site. The examples will be more advanced than those found in the first project, and they will demonstrate some of the powerful things you can do using JavaScript.

The exercises in the chapters are designed to give you a solid foundation in JavaScript on which you can build as you continue to use it. You will find that more often than not there is more than one way to do things in JavaScript — there really are no right or wrong ways to accomplish tasks.

For all of the examples in the book you can go to the companion Web site located at http://www.phptr.com/essential and download the HTML and images needed to follow along with the exercises.



An Introduction to JavaScript

What Is JavaScript?

For those of you who are new to the world of Web development and may be learning JavaScript in conjunction with HTML, a quick introduction to JavaScript may be in order. JavaScript is Netscape's built-in, cross-platform scripting language. Like HTML, it will work on all platforms. JavaScript allows you to enhance the functionality of your Web pages by embedding applications directly into your HTML. You can use JavaScript to bu ld appl cat ons that range from adding interactivity to your pages to applications that interact with databases. Although Netscape created JavaScript, it will work on most modern browsers, including Microsoft's Internet Explorer (IE). However, IE doesn't directly support JavaScript. IE has its own scripting language — JScript — that supports most of the features found in JavaScript. In the few instances in which the languages differ, those differences are pointed out and a workaround is presented. As these are the two main browsers on the market, the scripts we will be writing will focus on them.

There are two methods that you can use to include JavaScript in your Web pages — client-side and server-side. Both methods share the same basic language sets. This core language defines a base set of objects and features that will work in both client-side and server-side applications. Each method also has its own extended object and feature sets.


Client-Side JavaScript: How It Works

Client-side JavaScript applications are scripts that are embedded directly into your HTML pages and are executed by the user's browser as it loads the page. At least 90% of all the scripts you encounter on the Web fall into this category. Therefore, this is the method that we will use throughout this book.

When the user's browser calls up an HTML page with JavaScript embedded in it, the browser's JavaScript runtime engine interprets the script from the top down, executing statements as it goes.

One of the advantages of using client-side scripting is that the script can detect and make use of user-initiated events, such as changes to a form or the mouse rolling over a particular graphic. The script is then able to use that information to call other parts of the script, and all of this can be done without going back to the Web server and grabbing any more information. Because our scripts are dependent on being interpreted by the user's browser, a few words on the different browsers and how they differ in handling JavaScript are in order.


Browsers and Versions

As stated earlier, IE and Navigator differ slightly in the implementation of their scripting languages. As a programmer, this makes your life a little more difficult: There will be times when a solution will work differently or not at all on different browsers. Wait — it gets worse: As Netscape and Microsoft come out with newer versions of their browsers, the versions of their scripting languages are changing as well. This means that scripts written using new features may not work in an older browser. But don't get too upset — it's not as bad as it seems. All this means is that you will have to take a little extra care in writing and checking your scripts. There are many techniques that you can use to make sure your scripts will work across the board — we will be exploring these techniques and the appropriate times to use them. However, as this book has JavaScript in its title instead of JScript, we will be concentrating mainly on Netscape's scripting language.


What JavaScript Can and Can't Do

While the applications that you can create using JavaScript are only limited by your imagination, there are several things that you cannot do such as access or control the user's machine. For security reasons, writing to a user's computer is severely limited. You can store data on the user's machine only through the use of a cookie, and even then you are limited to a simple text file. This protects users from scripts that might harm their computers or allow unscrupulous programmers access to personal information.

A security feature called the "Same Origin Policy" also restricts the access of scripts from one origin access to certain properties or files from other locations. For example, if you have a script located at http://www.yoursite.com/test.html and it tries to access certain properties of an HTML page located at http://www.theirsite.com/ test.html, the Same Origin Policy will deny your script access. The properties that the Same Origin Policy restricts are show

Updates

Errata

Sorry for the trouble that you are having with the Form Validation project in Chapter 4 of the book. This was a problem that I thought I had corrected, but it must have slipped by our final tech checks. There are two places that need slight modifications, first in the script and secondly in the HTML for the pulldown menu. In the script the line in question that needs fixing is following (it should be around line 52).

     if (document.forms['promotion'].elements['whatTheyWant'].value == 'default')

We need to first add a new line of code right before this one:

     var selectPos =
document.forms['promotion'].elements['whatTheyWant'].selectedIndex;

What this line does is to create a variable called "selectPos" and assigns it the value of whichever item is selected from the pull-down menu. Next we need to modify our IF statement to use this new variable.

     var selectPos =
document.forms['promotion'].elements['whatTheyWant'].selectedIndex;

     if
(document.forms['promotion'].elements['whatTheyWant'].options[selectPos].value == 'default')

In this newly modified IF condition we are checking to see if the value of the option for the selected menu item is equal to "default." If this is the case then we go ahead and execute the code that is contained within the IF statement. Now that we have the script fixed we need to change a line in the HTML (around line 249).

This is the existing piece of code:

     <OPTION VALUE="">Please choose a category

Here is what we need to change it to:

     <OPTION VALUE="default">Please choose a category

All we are doing here is assigning the value "default" to this initial menu item. This lets us test for our IF statement up in the script.

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020