HTML Goodies: Script Tip: Week 6

By Joe Burns

We're underway with a new script. Here's the code again to get us up to date.

<SCRIPT LANGUAGE="javascript">

function JemWebCONFIRM()
{if (!confirm ("YOUR MESSAGE GOES HERE"))
history.go(-1);return " "}


In this Tip we're going to focus on that "function" up in the script. Here's the basic concept.

There are a lot of commands in JavaScript that do things. One command, one effect. But, as you probably know by now, you can also combine a bunch of those singular events into a secondary output. For instance, you can use a getDate() method to grab the date, then use another series of JavaScript commands to change the numeric value of the date into text, and finally post that text to the status bar. Generally, that would be done with three different commands, and you can certainly write it that way.

But wouldn't it be nice if you could set up those three commands and assign a title to it? One command would enact all three commands to get the desired effect. Well, you can! That's a function.

Above, the function is named JemWebCONFIRM(). See that? The format is to write the word "function" to denote that it is a function, then immediately offer a name for the function followed by the two parentheses (). The name of the function can be just about anything. The only function names usually frowned upon are those that already exist in the JavaScript language.

Okay, so you've named it. Now what's it going to do? Look again at the script above. Notice that right after the function name are some commands inside of those fancy brackets {}. That's what it will do. Whatever appears within the fancy brackets is what will occur when you call for the function. In this case, an alert window will pop up and do a few other things, but that's another Script Tip...

Next Week: What's With The Parentheses, Anyway?

     Do YOU have a Script Tip you'd like to share? How about suggesting a Script Tip to write about? I'd love to hear it. Write me at: jburns@htmlgoodies.com

Learn to write your own JavaScripts with the
HTML Goodies 30-Step Primer Series
and take the knowledge home with you in
JavaScript Goodies!

You can find many other uses for JavaScript
on your Web pages here!

  • Web Development Newsletter Signup

    Invalid email
    You have successfuly registered to our newsletter.
Thanks for your registration, follow us on our social networks to keep up-to-date