19.4. Uses for JavaScript

It's important to note a few things about JavaScript when deciding when and where you want to use it:

  • It is a client-based language. As such, it has very limited access to server-based resources (databases, and so on) and relies on the client supporting (and allowing) JavaScript to run.

  • It is a scripting language with definite limitations. More robust, server-side languages (Perl, Python, and PHP, also covered in this book) should be used for more capable applications.

  • JavaScript source code is visible in the documents in which it appears. Even external script files can usually be browsed with little effort. As such, you should never embed sensitive information in your scripts.

Even with those caveats taken into account, there are still many uses for JavaScript, including the following:

  • Form verification. JavaScript can parse form data prior to the data being submitted to a handler on the server, ensuring that there are no obvious errors (missing or improperly formatted data). Form verification is covered in Chapter 22.

  • Document animation and automation. Accessing element data and properties via the DOM, JavaScript can affect changes in elements' content, appearance, size, position, and so forth. By doing so, simple scripts can create simple animations — menu items that change color, images and text that move, and so on. Rudimentary dynamic content can also be achieved via JavaScript — custom content can be generated according to other behavior initiated ...

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.