"Randy Webb" <Hi************ @aol.comwrote in message
news:A4******** ************@te lcove.net...
Magician said the following on 12/25/2006 8:18 PM:
>Hello.
I am trying to set the onclick event for images through a function, but
the
event is triggered as soon the page loads, then will not work when the
image
is clicked. Can anyone suggest what is wrong?
It is happening in both IE6 and Firefox
---------------------------------------------------------------------------
window.onloa d = fnNewWindowLink s;
function fnNewWindowLink s() {
for (var intLinks=0; intLinks<docume nt.links.length ; intLinks++) {
if (document.links[intLinks].className == "picture") {
document.links[intLinks].onClick = alert("Clicked" );
Two things:
It is onclick in JS, not onClick
document.links[intLinks].onclick= new Function('alert ("Clicked")' )
--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/
Thanks Randy, I got that working, but when i try to extend it a bit further
to open an image in a window, it is going back to loading the window when
the page loads and not on the click event.
I am following examples is a js book and trying to adapt them for my
purposes but I can't get it working.
Is my problem now the call to the second function?
----------------------
window.onload = fnNewWindowLink s;
function fnNewWindowLink s() {
for (var intLinks=0; intLinks<docume nt.links.length ; intLinks++) {
if (document.links[intLinks].className == "picture") {
document.links[intLinks].onclick = fnNewWindow() ;
}
}
}
function fnNewWindow() {
var strImage = "creative/artwork/" + this.id + ".jpg";
var objWindow = window.open(str Image, "PictureWindow" ,"resizable=yes ");
return false;
}
---------------------------
Regards
Mag