www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] click to change image - not working

  1. #1
    Join Date
    May 2009
    Posts
    226

    resolved [RESOLVED] click to change image - not working

    I have the following code that is not working

    in the head tag

    HTML Code:
    <script type="text/javascript"> 
    
    function changeIt() 
    {
    var theImg = document.getElementsByTagName('img')[0].src;
    
    var x = theImg.split("/");
    var t = x.length-1;
    var y = x[t];
    
    if(y=='images/floor19.jpg')
    {
    document.images.example.src='images/floor19pg.jpg'
    }
    }
    </script>
    and the following in the body

    HTML Code:
    <img src="images/floor19.jpg" border="0" usemap="#Map2"  name='example' />
    
    <a href="#" onclick="changeIt()">Practice Groups</a>

  2. #2
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    Try changing name='example' to id='example'

    and

    var theImg = document.getElementsByTagName('img')[0].src;
    to
    var theImg = document.getElementByID('example').src;

  3. #3
    Join Date
    May 2009
    Posts
    226
    i have tried this with no success

    here is the error

    object doesn't support this property or method

  4. #4
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    do some troubleshooting

    add alert(theImg); and see what you get.

    Then get rid of all the other stuff and write a simple if statement

  5. #5
    Join Date
    May 2009
    Posts
    226
    it seems the original coding works if the graphics are taking out of the "images" folder and put on the main level

    is there a way to work the code so that i can leave the graphics in the "images" folder

  6. #6
    Join Date
    May 2009
    Posts
    226
    i have figured it out just the first image reference in the body needs to have the "images/

    and then it works

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles