Alert windows

This program shows how to create alert windows.

Programming Issues

Here we show the three flag images we have used in previous examples. When clicked, the script causes an alert window to appear telling the user which flag he clicked. We catch the onclick event for each of the three images, and call the alertImage() function passing an argument to let it know which of the three images we clicked. The code to create an alert box is: alert.("You clicked the Welsh flag!");.

Note we could, in this case, just as easily have embedded the JavaScript code into the event handler itself, as so: <img src="walesflag.png" onclick="javascript: alert('You clicked the Welsh flag!')" />. Note that we have to enclose the alert message in single rather than double quotes in this case, because double quotes are used to embed the code itself.

Demonstration

Welsh Flag Scottish Flag English Flag

Source and Downloads