0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Events !</title>
    <script type="text/javascript">
        window.onload = function() {
            document.getElementById('anImage').addEventListener('click', function() { alert('F-15 Tomcat'); }, false);
            document.getElementById('anImage').addEventListener('click', function() { alert('F-15 Tomcat again !'); }, false);
            document.getElementById('anImage').addEventListener('click',
                                               function() { Alert; }, 
                                               false);
        }
        function Alert() {
            alert('This is a Two Seater Aircraft .... !')
        }
    </script>
    <style type="text/css">
        #anImage
        {
            height: 275px;
            width: 357px;
        }
    </style>
</head>
<body>
   <img src="1012562.jpg" id="anImage" />
</body>
</html>

The Alert function is not being called in the third event .... !
Could anyone tell me what is wrong or a better way to call that function ????

Thanx

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by stbuchok
0

Capitalization matters.

Alert != alert

also

alert != alert() // the brackets indicate that you are executing the function.

0

Capitalization matters.

Alert != alert

also

alert != alert() // the brackets indicate that you are executing the function.

Ok ok .....

I changed "Alert;" to "Alert();" !
Now it executes the way I wanted !

But then when I used only "Alert" ... why didn't it show any error ??
:O

0

Because it's an allowable statement.

Also, don't create a function that is the same as another function but differs only by case. There is a built in alert function, by creating your own function called Alert, you are asking for trouble.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.