Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replacing One Image For Another with Javascript

    I am very new to javascript but I am running into an issue with a confirmation page I am building for a registration site. The default for the confirmation is to show all questions and user responses given. A colleague of mine used an image with an image map to create the selections. What happens is the confirmation page spews out the image along with all the other responses.

    Is there a way in javascript to exchange one image for another and to set the height and width parameters for the image that your replacing with?

  • #2
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nevermind everyone. I got it. Function below.

    <SCRIPT>
    function hideGraphics()
    {
    hideImage(' THE IMAGE LOCATION HERE ');
    }
    function hideImage(url)
    {
    if (document.images){for(i=0;i<document.images.length;i++)
    {
    if(document.images[i].src==url)
    {
    document.images[i].height=1;
    document.images[i].src==' IMAGE YOU WANT TO PUT IN PLACE ';
    }
    }
    }
    }
    </SCRIPT>

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    you may make it simplier and DOM compliant:
    PHP Code:
    <script type="text/javascript">
    function 
    changeImg(){
    var 
    imag document.getElementsByTagName('img');
    for(var 
    i=0;i<imag.length;i++){
    if(
    imag[i].getAttribute('src')=='THE IMAGE LOCATION HERE'){
    imag[i].removeAttribute('height');
    imag[i].setAttribute('src','IMAGE YOU WANT TO PUT IN PLACE');
    }
    }
    }
    </script> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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