Coding with JavaScript For Dummies
Book image
Explore Book Buy On Amazon
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
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

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
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:


About This Article

This article is from the book:

About the book authors:

Chris Minnick is an accomplished author, trainer, and web developer who has worked on web and mobile projects for both small and major businesses. Eva Holland is an experienced writer and trainer who has designed and taught online, in-person, and video courses. They are cofounders of WatzThis?

This article can be found in the category: