SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    add image src from javascript function

    Hello,
    I have a js function inside the head of a page of mine which takes 2 arguments that are created dynamically based on what I retrieve from a database.
    My question is whether I can set the attribute src of the <img> tag through the js function. What I have is:
    Code:
     <script type="text/javascript">
    function HideShow(myVar, mySecondVar) 
              { 
                    if (document.getElementById(myVar).style.display == 'none') 
                    { 
                        document.getElementById(myVar).style.display = 'inline'
                       -----> mySecondVar.src = "css/images/show.gif"
                    } 
                    else 
                    { 
                        document.getElementById(myVar).style.display = 'none'
                      ----->  mySecondVar.src = "css/images/hide.gif" 
                        }
              } 
    </script>
    The lines with the arrow in front of them do not work, presumably there is a mistake in the syntax because I see no image...

    I would greatly appreciate any help!

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Presumably mySecondVar is also the ID of an HTML element? If so, just do something similar to what you did for myVar:
    Code:
    document.getElementById(mySecondVar).src = "css/images/show.gif";


Bookmarks

Posting Permissions

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