Hello I am sorry to bother you with such a simple question but this bit of code, I literally could not find anything wrong with it, but none of the alerts even trigger so I know that init isn’t even been passed to window.onload. Here is the code:
window.onload()=init;
alert("The file has been linked to.");
function init(){
alert("Init has been loaded");
var button = document.getElementById("myButton");
button.onclick = handleButtonClick;
}
function handleButtonClick()
{
alert("button has been clicked");
var target = document.getElementById("target");
var image = document.createElement("<img />");
image.innerHTML = "<img src=../Images/banner_test.jpg alt=Banner height=42 width=42 />" ;
target.appendChild(image);
}
The JS is in a external js file I’ve linked to with:
<script type="text/javascript" src="../JS/Experiment.js" > </script>
Have I misspelt something or forgotten a parameter because as I’ve said none of the alarms will activate, no use talking about creating a new <img /> and adding it.
The HTML isn’t a problem I’ve tried a simple alert() with inline <script> and it works but I need this to be in a external file.
window.onloadis not a method, drop the parens()