Tutorials Books Videos Forums

Change the theme! Search!
Rambo ftw!

Customize Theme


Color

Background


Done

JavaScript Alerts

by Taylor Pennington aka DigitalPimp   | filed under Web, HTML, CSS, and XML

This is an archived tutorial from the kirupa.com legacy collection. It covers software that may no longer be available, but it is kept online because the ideas still hold up.

This is an introduction in using Javascript with a web page. I am first off going to show you how to write a function in Javascript and then I will show you how to call it out using HTML. Javascript is A LOT like ActionScript, it uses dot notation and functions.

Anywho, let's get to learning, first off let's dissect a function. A function is something that you make to process data or create an action. In this case we are going to do the simple of simple functions, we are just going to make an alert pop-up. Alerts are very useful and are similar to the trace feature in AS.

The Code:

  <SCRIPT>
function alertUser() {
  alert("Hello World");
}
</SCRIPT>

Copy and paste that code into a HTML page. Now that we have written the function we need to write some code on the page to activate or 'set it off' if you the will the function because the browser has processed the function but it doesn't know when to make the function process. This is similar to doing an onRelease or onClipEvent in AS.

What we are going to do is use a hyperlink to set off this function. Now in a hyperlink you have many many actions that you can do to activate it just like in AS.

These are all the events:

To use the above actions, you will need to, as mentioned earlier, call them. The following syntax can be used:

<a

  event="functionName"
  href="javascript:void(0)">Click Me</a>

So, if you want to call the onClick example, your code will look similar to the following line of code:

<a

  onClick="alertUser()"
  href="javascript:void(0)">Click Me</a>

The event is onClick and the name of our function is alertUser(). I told you this would not be very complicated. The following list displays all of the aforementioned events as examples for you to interact with:

If you have any questions, feel free to post you in the Scripting forum for help.

Much Respect,

DigitalPimp

Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy kirupa's books, became a paid subscriber, watch the videos, and/or interact on the forums.

Your support keeps this site going! 😇

The KIRUPA Newsletter

Thought provoking content that lives at the intersection of design 🎨, development 🤖, and business 💰 - delivered weekly to over a bazillion subscribers!

SUBSCRIBE NOW

Creating engaging and entertaining content for designers and developers since 1998.

Follow:

Popular

Loose Ends

:: Copyright KIRUPA 2026 //--