Jump to content
  • Advertisement

Archived

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

Craazer

Is there a way around this?

This topic is 5533 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!