ad info

 
CNN.com  technology > computing
    Editions | myCNN | Video | Audio | Headline News Brief | Feedback  

 

  Search
 
 

 
TECHNOLOGY
TOP STORIES

Consumer group: Online privacy protections fall short

Guide to a wired Super Bowl

Debate opens on making e-commerce law consistent

(MORE)

TOP STORIES

More than 11,000 killed in India quake

Mideast negotiators want to continue talks after Israeli elections

(MORE)

MARKETS
4:30pm ET, 4/16
144.70
8257.60
3.71
1394.72
10.90
879.91
 


WORLD

U.S.

POLITICS

LAW

ENTERTAINMENT

HEALTH

TRAVEL

FOOD

ARTS & STYLE



(MORE HEADLINES)
*
 
CNN Websites
Networks image


Tutorial: A gentle introduction to JavaScript

MacWorld Online

(IDG) -- Welcome to my JavaScript tutorial! This is an introductory-level piece, with the goal of teaching JavaScript to those of you who've worked with HTML before and are now thinking about taking that next step forward. To start, I'll cover what JavaScript is (and isn't).

What Is JavaScript?

JavaScript is what's known as a scripting language, which means that it is (in general) easier to learn than a full-blown programming language such as C++ or Java. You don't need any special tools, programs, or compilers to write JavaScript; whatever you're currently using to write HTML should work just fine. Personally, I prefer to use Bare Bones Software's BBEdit, but WYSIWYG tools such as Adobe GoLive and Macromedia Dreamweaver will do the trick, too. Some people are happy coding their pages with SimpleText, but that's a little too minimalist for my taste. If you don't have any of these (except SimpleText, of course), check out the freeware BBEdit Lite.

MORE COMPUTING INTELLIGENCE
IDG.net   IDG.net home page
  MacWorld Online home page
  Updated Flash is easier on newbies
  Web graphics overview
  Wake up your Web sites
  Reviews & in-depth info at IDG.net
  E-BusinessWorld
  TechInformer
  Questions about computers? Let IDG.net's editors help you
  Subscribe to IDG.net's free daily newsletters
  Search IDG.net in 12 languages
  News Radio
  * Fusion audio primers
  * Computerworld Minute

JavaScript can be used to make your Web pages interactive and dynamic. A static HTML page without any JavaScript just sits there -- if a visitor returns to your site next week, it'll look exactly the same as it did today. With JavaScript, you can display different images, give feedback on forms, control the user's browser (for instance, displaying different pages based on the user's plug-ins), and manage framed sites. Overall, you use JavaScript to give the user feedback: the feeling that your site is responsive to their actions.

The most common use of JavaScript is the ubiquitous image rollover. It's gotten to the point on the Web where if you don't use JavaScript to change your clickable buttons, some users won't click on them, as they won't realize that they have that option. Image rollovers have become a de facto Web user interface standard, so you should use them if you want to give your visitors the experience they expect.

Other feats you can accomplish with images include slide shows, displaying random graphics, and making images move around the browser window. With JavaScript and forms, you can validate that the information has been entered correctly, cross-check fields against each other, and use one field to set another. With JavaScript and frames, you can force your site either into or out of a frame set, as well as to use information in one frame to change the display of another. You can also change your page based on the date, time, browser, available plug-ins, and/or platform of your site's visitors.

JavaScript is sometimes referred to as JScript or ECMAScript. These aren't exactly the same languages as JavaScript, but the name JavaScript is often used to include them, too.

What JavaScript Isn't

There are a number of common misconceptions about JavaScript. I'll just clear them up now.

JavaScript Isn't Java

At one time, Netscape added a little scripting language to Navigator 2, which they called LiveScript. They had high hopes for this language, but hardly anyone paid attention to it -- most of the mindshare was being given to a new language called Java, which had been recently released by Sun Microsystems. At that point, if you believed some of the press reports, Java was going to cure cancer, feed the hungry, and bring about world peace. How could a new little scripting language compete against that?

The marketing department at Netscape decided that it was better to switch than fight, and (with permission from Sun) changed the name of LiveScript to JavaScript. After that, getting attention became much easier. Unfortunately, this led to the common side effect that many people think that they're the same language, or that JavaScript is a "light" version of Java, or that Sun invented JavaScript. None of these stories are true, and the only thing that the two have in common are the first four letters.

JavaScript Isn't a Security Risk

This myth started due to a number of horror stories that tried to convince everyone that they should turn JavaScript off because otherwise, bad, bad things could happen to you. The stories just aren't true. There are no verified reports of anyone, ever, using JavaScript by itself in a way that creates a security hole on a live site. And in every case where someone has written an exploit using JavaScript combined with a server-side program, the hack could have been done just as well without JavaScript. So go ahead and turn JavaScript on; it won't bite.

JavaScript Can't Do Everything

While I wish that JavaScript could do everything, it can't. JavaScript can't read from or write to your hard drive, and JavaScript can't send email. JavaScript also can't get rid of the need for server-side programs; for instance, you can't use it to keep track of visit counters or store form info in a database.

With this information under your belt, you'll be ready to start coding. Stay tuned for the next installment!

For an unabridged version of this story, click here.




RELATED STORIES:
Sun opens up Java specification process -- somewhat
June 5, 2000
Newest version of 'desktop Java' runs fast
May 11, 2000
Learn Java from the ground up
April 5, 2000
Rollover effects made easy
April 5, 2000
Sun looking to heat up Java performance
January 12, 2000

RELATED IDG.net STORIES:
The secret to elegant & versatile site
MacWorld
Updated Flash is easier on newbies
PC World
Web graphics overview
MacWorld
Design that divides: The disabled speak up
Industry Standard
Web design workshop: Easy mouseovers
Publish
Wake up your Web sites
MacWorld
New animator makes Java easy
PC World
Webby awards seek entries
PC World

RELATED SITES:
Download BB Edit Lite here

Note: Pages will open in a new browser window
External sites are not endorsed by CNN Interactive.

 Search   

Back to the top   © 2001 Cable News Network. All Rights Reserved.
Terms under which this service is provided to you.
Read our privacy guidelines.