In my code, I have this:
<IMG SRC="images/leaf_shapes/entire/transparent1.gif" name="pic4" width="250" height="350" border="0">

I need to have it change in a image, but only if it still says 'transparent1.gif' (because it could have been changed already and I don't want to lose that change)

I basically want to do something like this pseudo-script below, but I don't know javascript enough to know exactly how to write it:

<script>

function change1(picName,imgName)
"if image file 'pic4' = transparent1.gif (and not anything else) {

{
if (document.images)
{
imgOn=eval(imgName + ".src");
document[picName].src= imgOn;
}
} else { do nothing to pic4}

    Salutations!

    Give the IMG an ID instead of a Name.

    <IMG SRC="images/leaf_shapes/entire/transparent1.gif" width="250" height="350" border="0" id="pic4">
    function change1(picName, imgName){
       var imageElement = document.getElementById(picName);
       if(imageElement.src == "images/leaf_shapes/entire/transparent1.gif"){
           imageElement.src = "images/leaf_shapes/entire/" + imgName;
       }
    }
    

    I am not entirely sure what path src gives, but it should be something like that. Use alerts() to see how the code works or get Firebug to debug the code step by step.

      What you wrote seems to be exactly what I need, but it's somehow not making the change. The alert shows it's still the original url. Here's what I have:

      function changecolor(picName,imgName){
      var imageElement = document.getElementById(picName);
      if(imageElement.src == "/images/leaf_shapes/entire/transparent1.gif"){
      imageElement.src = "/images/leaf_shapes/entire/" + imgName;
      }alert(imageElement.src);
      }

        Hey again,

        That probably means that the check isn't fully correct, make sure that it actually goes into the if-case.

          Write a Reply...