Jump to content

script to check what a pic's name is and change it if it matches.


turpentyne

Recommended Posts

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;
    }
}

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; }
}

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.