What Can I Do with JavaScript That I Can't Do with Web Languages?

HTML. DHTML. XML. JavaScript. Java. Flash. When it comes to Web development, the sheer array of languages and development tools can be confusing — and you might be left wondering which language is best for which task.

The fact is that each language was designed with a particular kind of task in mind, and JavaScript is no exception. Table 1 shows you the types of tasks that JavaScript is best (and least) suited to perform. JavaScript is best suited for client-side (browser-based) tasks.

Table 1: Using JavaScript for the Right Task

Task

Is JavaScript Useful?

Are JavaScript and CSS (DHTML) Useful?

Provide users with helpful feedback

Yes

No

Customize page appearance

Yes

Yes (more sophisticated than JavaScript alone)

Examine or change HTML form data

Yes

No

Create simple animations

Yes

Yes (more sophisticated than JavaScript alone)

Create complex animations

No

No

Perform server-side processing

No

No

JavaScript performs its magic by working together with HTML and cascading style sheets (CSS). Here's how it works: HTML and CSS let you create static Web pages by using tag building blocks, or objects. JavaScript lets you inspect and manipulate the objects to punch up static pages with interactivity and simple animations. (In other words, to use JavaScript, you need to use HTML; to take advantage of dynamic HTML, or DHTML, features, you need to use both HTML and CSS.)

By using JavaScript, you can make a Web site easy to navigate and even customize your page depending on who's viewing it, what browser the visitor is using to view it, and what time of day it is. You can even create simple (but effective) animated effects.

Make your Web site easy for folks to navigate

The most common way to perk up your pages with JavaScript is to make them easier to navigate. For example, you can use JavaScript to

  • Create expandable site maps.
  • Add tooltips — helpful bits of text that appear when a user moves a mouse over a particular section of your Web site.
  • Swap images when a user drags a mouse over a certain area of the screen. (This effect is called a mouse rollover, and it helps users determine at a glance which parts of your Web page are interactive, or clickable.)
  • Inspect the data that your users enter and pop up helpful suggestions if they make an invalid entry.
  • Display a thank-you message after a user submits a form.
  • Load content into multiple frames when a user clicks a button so that the user can view multiple chunks of related information at the same time.

In addition to user-initiated events, such as clicking and dragging a mouse, JavaScript also recognizes automatic events — for example, loading a Web page onto a browser.

Customize the way your Web site looks on-the-fly

Everyone likes to feel special, and the folks who visit your Web site are no exception. By using JavaScript, you can tailor the way your pages look to different users based on criteria such as

  • The specific kinds and versions of browser that visitors use to view your page
  • The current date or time
  • Your users' behaviors the last time they visited your pages
  • Your users' stated preferences
  • Any other criteria you can imagine

Create cool, dynamic animated effects

Many folks assume that you need Java to create animations for the Web, but that's just not so. Although JavaScript certainly won't be mistaken for the most efficient way to create high-density animations, you can use JavaScript with cascading style sheets (the combination is sometimes known as DHTML) to create a variety of really neat animated effects. As a matter of fact, using JavaScript is the easiest way to implement common effects, such as rollovers.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.