Java Reference
In-Depth Information
Why Choose JavaScript?
JavaScript is not the only scripting language; there are others such as VBScript and Perl. So why choose
JavaScript over the others?
The main reason for choosing JavaScript is its widespread use and availability. Both of the most commonly
used browsers, IE and Firefox, support JavaScript, as do almost all of the less commonly used browsers.
So you can assume that most people browsing your web site will have a version of JavaScript installed,
though it is possible to use a browser's options to disable it.
Of the other scripting languages already mentioned, VBScript, which can be used for the same pur-
poses as JavaScript, is supported only by Internet Explorer running on the Windows operating system,
and Perl is not used at all in web browsers.
JavaScript is also very versatile and not just limited to use within a web page. For example, it can be
used in Windows to automate computer-administration tasks and inside Adobe Acrobat PDF fi les to
control the display of the page just as in web pages, although Acrobat uses a more limited version of
JavaScript. However, the question of which scripting language is more powerful and useful has no real
answer. Pretty much everything that can be done in JavaScript can be done in VBScript, and vice versa.
What Can JavaScript Do for Me?
The most common uses of JavaScript are interacting with users, getting information from them, and
validating their actions. For example, say you want to put a drop-down menu on the page so that users
can choose where they want to go to on your web site. The drop-down menu might be plain old HTML,
but it needs JavaScript behind it to actually do something with the user's input. Other examples of using
JavaScript for interactions are given by forms, which are used for getting information from the user. Again,
these may be plain HTML, but you might want to check the validity of the information that the user is
entering. For example, if you had a form taking a user's credit card details in preparation for the online
purchase of goods, you'd want to make sure he had actually fi lled in those details before you sent the
goods. You might also want to check that the data being entered are of the correct type, such as a num-
ber for his age rather than text.
JavaScript can also be used for various tricks. One example is switching an image in a page for a differ-
ent one when the user rolls her mouse over it, something often seen in web page menus. Also, if you've
ever seen scrolling messages in the browser's status bar (usually at the bottom of the browser window)
or inside the page itself and wondered how that works, this is another JavaScript trick that you'll learn
about later in the topic. You'll also see how to create expanding menus that display a list of choices
when a user rolls his or her mouse over them, another commonly seen JavaScript-driven trick.
Advances in browser sophistication and JavaScript mean that modern JavaScript is used for much more
than a few clever tricks. In fact, quite advanced applications can be created. Examples of such applications
include Google Maps, Google Calendar, and even a full-fl edged word processor, Google Docs. These
applications provide a real service. With a little inventiveness, you'll be amazed at what can be achieved.
Of course, while JavaScript powers the user interface, the actual data processing is done in the back-
ground on powerful servers. JavaScript is powerful but still has limits.
Search WWH ::




Custom Search