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 by the user. Dynamic HTML (the name for the technology of JavaScript manipulating document objects and elements) is covered in Chapters 23 and 24.

  • Basic document intelligence. As mentioned in the preceding bullet, JavaScript can initiate changes in documents based on other, dynamic criteria. Using JavaScript you can embed a base level of intelligence and an extra layer of user interface in your documents. Elements can be linked to scripts via events (onclick, onmouseover, and so on) to help the user better use your documents. Sample uses of triggers can be found in Chapter 22.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.5.86