views:

38

answers:

1

Hi,

I have a javascript function, I want it to be called programatically on init and later onClick event but its not getting called programatically but works ok with onClick.

The example would be:

function init() {
  a(); 
}

init() is called on initialization which should call a() but thats not happening!

+2  A: 

Here is the example working 100 %

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
    <title>sdasddss</title>


    <script type="text/javascript">
  function init(){
alert("I'm calling afunction()");
afunction();
}

function afunction(){
alert("I was called successfuly");
}

window.onload = init;
  </script>

</head>

<body>

My body

</body>
</html>
c0mrade