-2

http://code.tutsplus.com/tutorials/the-basics-of-object-oriented-javascript--net-7670

the above tutorial tells that :

$(document).ready(function(){
    //all our code that runs after the page is ready goes here
});

And

 addEvent(window, 'load', function(){
        //all our code that runs after the page is ready goes here
    });

are same . So i am trying to use addEvent like this :

<html>
<head>

<script type="text/javascript">

addEvent(window, 'load', function(){
    alert("test");
});
</script>

</head>
<body>

<form id="ourForm">
    <label>First Name</label><input type="text" /><br />
    <label>Last Name</label><input type="text" /><br />
    <label>Email</label><input type="text" /><br />
    <input type="submit" value="submit" />
</form>

</body>

</html> 

But i am getting error : Uncaught ReferenceError: addEvent is not defined

Please help. I am new to javascript

Sid M
  • 4,354
  • 4
  • 30
  • 50
Abhishek Kumar
  • 2,136
  • 3
  • 24
  • 36

1 Answers1

0

Tutorial contains the addEvent function. Please check.

function addEvent(to, type, fn){
    if(document.addEventListener){
        to.addEventListener(type, fn, false);
    } else if(document.attachEvent){
        to.attachEvent('on'+type, fn);
    } else {
        to['on'+type] = fn;
    }  
};

You can use Jquery events instead of this method.

http://api.jquery.com/category/events/

Saranga
  • 3,178
  • 1
  • 18
  • 26