I apologise for what seems to be a simplistic problem, hopefully with a simplistic solution. I have written an image gallery script with 3 functions – one for 3 separate events as follows:
[code=php]<body onload=”loadnum()”>
<input type=”button” name=”previous” value=”Previous image” onclick=”goback()”>
<input type=”button” name=”next” value=”Next image” onclick=”advance()”>
But now I have decided to register event handlers to these elements within the script. I am using Internet Explorer 6.
I have tried test after test, searched this forum, tried the addEventListener() method and the attachEvent() method but I have only had success with the document and window objects. I cannot set onclick or any other events with any of their properties or collections – images[], form.elements[] etc.
In other words, this works for me:
[code=php]document.onclick=dosomething;
However none of these approachs will work for me:
[code=php]document.getElementById(‘imgnum’).onclick=function(){alert(‘event added’);};
document.form1.next.onclick=advance;
document.form1.elements(‘next’).onclick=advance;
Could someone please point out where I have gone wrong or post a code that is sure to work?