Cheat Sheet

JavaScript For Dummies

JavaScript opens up Web pages to you so that you can add interactive features and those user-friendly touches. Of course, you have to know how to fit JavaScript into existing code and what to input to get the effects you want. And, when things aren't working well, you may need a little help troubleshooting the problem to get back on track.

JavaScript Object Terms

JavaScript is an object-based language. To understand how to interact with the document object model you work with in JavaScript, you need to understand some basic object-related terms. The following table shows the ones you're likely to find most useful:

Term JavaScript example
An object is a thing (noun). A button is an object.
You can describe an object with adjectives (properties). A button object has a name and a type.
An object can do things (methods). A button object can click().
An object can respond to events (event handlers). A button can recognize when it's been clicked (onClick).

Create a Hyperlink, Load a Web Page, and More with JavaScript

JavaScript helps you include all sorts of fun and interactive elements on a Web page, and the following table shows you how to do the kinds of tasks you want to be able to do with JavaScript. Whether you want to load a Web page or copy some code, check for the how-to here:

To Do This Do This in Navigator Do This in Internet Explorer
Load a JavaScript-enabled Web page Double-click on the Navigator icon of a file on your machine; or File→Open Page File→Open
Look at someone else's JavaScript code View→Page Source View→Source
Find a JavaScript-related news group Window→ Mail & Newsgroups Tools→Mail and News→Read News
Copy and paste someone else's JavaScript code Ctrl+C to copy; Ctrl+V to paste Ctrl+C to copy; Ctrl+V to paste
Create a hyperlink <A> . . . </A> <A> . . . </A> Create an HTML form <FORM> . . . </FORM <FORM> . . . </FORM

Troubleshooting JavaScript

JavaScript is a wonderful tool to use to create interesting and interactive Web pages, but every once in a while nothing works and you have no idea where to start to get things moving again. Not to worry; take a look at the following list for hints on what to do to get back on track (try them in this order):

  • Is your Web browser installed and configured correctly, including your communications stuff?

  • Is JavaScript enabled?

    From Navigator: Choose Edit→Preferences→Advanced→Scripts & Plugins and select the Enable JavaScript For Navigator check box.

    From Internet Explorer:

    • Choose Tools→Internet Options and click the Security tab

    • Click the Custom Level button

    • Scroll down until the Scripting category appears

    • Select the Enable radio button for these options: Active Scripting; Allow Paste Operations Via Script; and Scripting of Java Applets

  • Are all your JavaScript statements between <SCRIPT> and </SCRIPT> tags (except JavaScript statements attached to event handlers, which don't have to be)?

  • Does your HTML file work as it should by itself if you delete your JavaScript statements?

  • Do the names of your JavaScript variables all start with an alphabetic character (or an underscore)?

JavaScript Basic Cross-Browser Document Object Model

Like any other language, JavaScript has its own grammar and syntax — rules you need to follow to be understood. The following document object hierarchy lists the built-in objects you can work with in client-side JavaScript, along with their relationships to each other:

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

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.