Jump to content

avoid eval


IceDragon

Recommended Posts

hi

how do i avoid eval in the following script?? apparently it aint good.

i want to create a pic-link.. when u mouseon (put mouse on the pic) the pic becomes colorful, when u mouseout its black and white..

 

the problem is when u refresh page the pic-link is colorful when it should appear black and white.. and then when u go over it with mouse and out of the pic it becomes black and white.. it should be black and white when u refresh page.

 

does it have to do something with eval?

 

 

  if (document.images)
   {
     pic1on= new Image(195,130);
     pic1on.src="img/image1.jpg";  

     pic1off= new Image(195,130);
     pic1off.src="img/image1_2.jpg";

   }

function lightup(imgName)
{
   if (document.images)
    {
      imgOn=eval(imgName + "on.src");
      document[imgName].src= imgOn;
    }
}

function turnoff(imgName)
{
   if (document.images)
    {
      imgOff=eval(imgName + "off.src");
      document[imgName].src= imgOff;
    }
}

<a href="test.php" onMouseover="lightup('pic1')" onMouseout="turnoff('pic1')"><img src="img/image1.jpg" name="pic1" width="195" height="130"></a>

 

 

Link to comment
https://forums.phpfreaks.com/topic/88745-avoid-eval/
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.