On CBS News: 60 Min: Dire times for Iraq's Christians

Learn some hands-on JavaScript

Tags: Guest Contributor

  • Save
  • Print
  • Digg This
  • 0

Takeaway: Here's some hands-on JavaScript information and code for beginners.

By Emily A. Vander Veer

Before you dive into JavaScript code, you need to know the tags for embedding JavaScript into your pages.

<HTML>
<HEAD>

These are the standard tags to start an HTML page. It's good practice to put the JavaScript code between the <HEAD> and </HEAD> tags so that functions don't get called accidentally before the JavaScript is loaded.

<SCRIPT LANGUAGE="JavaScript">

This tells the browser that JavaScript code is about to appear. You may also specify the version of JavaScript in the LANGUAGE attribute, which will cause browsers that do not recognize that version to ignore it. For example, if you specified "LANGUAGE=JavaScript 1.2", any version of Navigator below 4.0 would not process the script.

<!--

This is a safety valve. Everything between the <!-- and the --> below will be ignored by browsers that can't interpret JavaScript.

// put your JavaScript statements below

The // is a JavaScript comment indicator that tells the browser's JavaScript interpreter to ignore the following text.

function someFunction() {
some JavaScript statements
}

This is where the actual JavaScript goes. The curly braces surround each statement and separate them from other statements in the function. Don't know what a statement is? You will.

// -->
</SCRIPT>

These indicate that we're all done with the script and can go back to HTML code.

</HEAD>
<BODY>
<FORM>
<!-- put your HTML statements below -->
<INPUT TYPE="button" NAME="someButton" VALUE="Press Me" onClick="someFunction()">

In this case, we tell the browser to run the JavaScript function someFunction() when the user clicks a button.

</FORM>
</BODY>
</HTML>

That's the end of the page. Everything's ready to run when a user loads the page into a JavaScript-ready browser. Here's a template code that you can cut and paste. Click here.

Emily A. Vander Veer is the author of numerous Internet-related magazine articles and books, including JavaScript for Dummies, JavaScript for Dummies Quick Reference, and JavaBeans for Dummies, all published by IDG Books.

  • Save
  • Print
  • Digg This
  • 0

What do you think?


advertisement
Click Here