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...
*/
}
}
Is there a way around this?
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?
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>''); } }
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!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement