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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.