turpentyne Posted May 1, 2011 Share Posted May 1, 2011 I have this code that simply changes an image when something is selected in a form. It finds this image name "pic4" and changes its file path "transparent1.gif" to green.gif, or orange.gif, depending on what was selected. The image code at the start: <IMG SRC="images/leaf_shapes/entire/transparent1.gif" name="pic4" width="250" height="350" border="0"> But I want it to only do so if "pic4" is still "transparent1.gif" as there's another button choice that it could be overriding. Any thoughts on how? I'm new to javascript. function change1(picName,imgName) { if (document.images) { imgOn=eval(imgName + ".src"); document[picName].src= imgOn; } } Link to comment https://forums.phpfreaks.com/topic/235247-script-to-check-what-a-pics-name-is-and-change-it-if-it-matches/ Share on other sites More sharing options...
turpentyne Posted May 2, 2011 Author Share Posted May 2, 2011 An update: I've gotten this far, but it still doesn't work at all. function changecolor(picName,imgName) { var leafcolor = document.getElementById('picName').src; if (leafcolor == "/images/leaf_shapes/entire/transparent1.gif") { document.getElementById('picName').src="/images/leaf_shapes/entire/leafbg_green.gif" } else { imgOn = eval(imgName + ".src"); document[picName].src= imgOn; } } Link to comment https://forums.phpfreaks.com/topic/235247-script-to-check-what-a-pics-name-is-and-change-it-if-it-matches/#findComment-1209254 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.