Archived

This topic is now archived and is closed to further replies.

Craazer

Is there a way around this?

Recommended Posts

Craazer    122
Hi heres a simple function wich should but two images to web page and display alert box whit greeting string when cursor is above the image(s). But it doesn''t work becose i comes undefined or if the i would be global it would always be 1 and so both alert boxes would show "Hi". So is there anyway to make this work in javascript?
  
var msgs = new Array("Helloy","Hi!")

function Doit()
{
for(i=0; i < 2;i++)
{
document.write(''<p><img border="0" src="pic.bmp" width="32" height="32"'')
document.write(''OnMouseOver="alert(msgs[i])"></p>'') // doesn''t work becose i is undefined

/*
if(i == 0) document.write(''OnMouseOver="alert(msgs[0])"></p>'') 
if(i == 1) document.write(''OnMouseOver="alert(msgs[1])"></p>'') 
// this should work!? but it''s dirty coding...
*/
}
}
  

Share this post


Link to post
Share on other sites
pag    100
You have to do it this way:>


  
var msgs = new Array("Helloy","Hi!")

function Doit()
{
for(i=0; i<2;i++)
{
document.write(''<p><img border="0" src="pic.bmp" width="32" height="32"'');
document.write(''OnMouseOver="alert(msgs[''+i+''])"></p>'');
}

}

Share this post


Link to post
Share on other sites
Craazer    122
quote:
Original post by pag
You have to do it this way:>



    
var msgs = new Array("Helloy","Hi!")

function Doit()
{
for(i=0; i<2;i++)
{
document.write(''<p><img border="0" src="pic.bmp" width="32" height="32"'');
document.write(''OnMouseOver="alert(msgs[''+i+''])"></p>'');
}

}


Ooh nice trick, thanks pag!

Share this post


Link to post
Share on other sites