Sams Teach Yourself JavaScript in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- We Want to Hear from You!
- Reader Services
- Introduction
- Part I: Getting Started
- Hour 1. Understanding JavaScript
- Hour 2. Creating a Simple Script
- Hour 3. How JavaScript Programs Work
- Part II: Learning JavaScript Basics
- Hour 4. Using Functions and Variables
- Hour 5. Using Strings and Arrays
- Hour 6. Testing and Comparing Values
- Hour 7. Repeating Yourself: Using Loops
- Hour 8. Using Math and Date Functions
- Part III: The Document Object Model (DOM)
- Hour 9. Working with the Document Object Model
- Hour 10. Responding to Events
- Hour 11. Using Windows and Frames
- Hour 12. Getting Data with Forms
- Hour 13. Using Graphics and Animation
- Part IV: Moving on to Advanced JavaScript Features
- Hour 14. Creating Cross-Browser Scripts
- Hour 15. Creating Custom Objects
- Hour 16. Working with Sounds and Plug-Ins
- Hour 17. Debugging JavaScript Applications
- Part V: Working with Dynamic HTML (DHTML)
- Hour 18. Working with Style Sheets
- Hour 19. Using Dynamic HTML (DHTML)
- Hour 20. Using Advanced DOM Features
- Part VI: Putting It All Together
- Hour 21. Improving a Web Page with JavaScript
- Hour 22. Creating a JavaScript Game
- Hour 23. Creating DHTML Applications
- Hour 24. JavaScript Tips and Tricks
- Part VII: Appendices
- Appendix A. Other JavaScript Resources
- Appendix B. Tools for JavaScript Developers
- Appendix C. Glossary
- Appendix D. JavaScript Quick Reference
- Appendix E. DOM Quick Reference
Alternatives to JavaScript
JavaScript is not the only language used on the Web, and in some cases, it may not be the right tool for the job. Other languages, such as Java, can do some things better than JavaScript. In the following sections, we'll look at a few other commonly used Web languages and their advantages.
Java
Java is a programming language developed by Sun Microsystems that can be used to create applets, or programs that execute within a Web page.
Java is a compiled language, but the compiler produces code for a virtual machine rather than a real computer. The virtual machine is a set of rules for bytecodes and their meanings, with capabilities that fit well into the scope of a Web browser.
The virtual machine code is then interpreted by a Web browser. This allows the same Java applet to execute the same way on PCs, Macintoshes, and UNIX machines, and on different browsers.
At this point, we need to make one thing clear: Java is a fine language, but you won't be learning it in this book. Although their names and some of their commands are similar, JavaScript and Java are entirely different languages.
ActiveX
ActiveX is a specification developed by Microsoft that allows ordinary Windows programs to be run within a Web page. ActiveX programs can be written in languages such as Visual C++ and Visual Basic, and they are compiled before being placed on the Web server.
ActiveX applications, called controls, are downloaded and executed by the Web browser, like Java applets. Unlike Java applets, controls can be installed permanently when they are downloaded, eliminating the need to download them again.
ActiveX's main advantage is that it can do just about anything. This can also be a disadvantage: Several enterprising programmers have already used ActiveX to bring exciting new capabilities to Web pages, such as "the Web page that turns off your computer" and "the Web page that formats your disk drive. "
Fortunately, ActiveX includes a signature feature that identifies the source of the control and prevents controls from being modified. While this won't prevent a control from damaging your system, you can specify which sources of controls you trust.
ActiveX has two main disadvantages. First, it isn't as easy to program as a scripting language or Java. Second, ActiveX is proprietary: it works only in Microsoft Internet Explorer, and only under Windows platforms.
VBScript
VBScript, sometimes known as Visual Basic Scripting Edition, is Microsoft's answer to JavaScript. Just as JavaScript's syntax is loosely based on Java, VBScript's syntax is loosely based on Microsoft Visual Basic, a popular programming language for Windows machines.
Like JavaScript, VBScript is a simple scripting language, and you can include VBScript statements within an HTML document. To begin a VBScript script, you use the <script LANGUAGE="VBScript"> tag.
VBScript can do many of the same things as JavaScript, and it even looks similar in some cases. It has two main advantages:
- For those who already know Visual Basic, it may be easier to learn than JavaScript.
- It is closely integrated with ActiveX, Microsoft's standard for Web-embedded applications.
VBScript's main disadvantage is that it is supported only by Microsoft Internet Explorer. JavaScript, on the other hand, is supported by Netscape, Internet Explorer, and several other browsers. JavaScript is a much more popular language, and you can see it in use all over the Web.
CGI and Server-Side Scripting
CGI (Common Gateway Interface) is not really a language, but a specification that allows programs to run on Web servers. CGI programs can be written in any number of languages, including Perl, C, and Visual Basic.
Along with traditional CGI, scripting languages such as Microsoft's Active Server Pages, Java Server Pages, Cold Fusion, and PHP are often used on Web servers. A server-side implementation of JavaScript is also available.
Server-side programs are heavily used on the Web. Any time you type information into a form and press a button to send it to a Web site, the data is processed by a server-side application.
The main difference between JavaScript and server-side languages is that JavaScript applications execute on the client (the Web browser) and server-side applications execute on the Web server. The main disadvantage of this approach is that, since the data must be sent to the Web server and back, response time may be slow.
On the other hand, CGI can do things JavaScript can't do. In particular, it can read and write files on the server and interact with other server components, such as databases. While a client-side JavaScript program can read information from a form and then manipulate it, it can't store the data on the Web server.
Summary | Next Section

Account Sign In
View your cart