IceDragon Posted January 31, 2008 Share Posted January 31, 2008 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 More sharing options...
nogray Posted January 31, 2008 Share Posted January 31, 2008 First, you'll need to give your images some ids <img src="img/image1.jpg" name="pic1" width="195" height="130" id="pic1"> and change the eval to getElementById() imgOn= document.getElementById(imgName + "on").src; Link to comment https://forums.phpfreaks.com/topic/88745-avoid-eval/#findComment-454789 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.