html image swapping problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • goal2007
    New Member
    • Jul 2007
    • 25

    html image swapping problem

    I spent hours trying to find an example of
    onMouseOver and onMouseOut and OnClick. I did find somethings about
    onMouseOver and onMouseOut but not the onClick.

    can you please help me with an example

    Thanks
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    Did you use Google? There should be millions of examples. In any case, this is not a html question so I'll transfer you to the javascript board.

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      hi ...

      please post some code you have done and tell where you have particular problems with it ...

      kind regards

      Comment

      • Death Slaught
        Top Contributor
        • Aug 2007
        • 1137

        #4
        "Hours" your exagerating, any search engine would have and will give you an example instantly, if you were look through a book I advise you burn it, or sell it on ebay, it will be no use to you if it doesn't even have basic material in it.

        Here's a tutorial on JavaScript I highly advise you read it all and do so carefully.

        If you had read the Posting Guidelines , you would have seen that we are not aloud to simply give you the answer, however, we are aloud to point you in the right direction. After reading the tutorial I gave you, if you are still confused about something feel free to post again, but try it on your own first, and post your code, then we will be glad to help you further.


        Hope it helps, Thanks, Death

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by goal2007
          I spent hours trying to find an example of
          onMouseOver and onMouseOut and OnClick. I did find somethings about
          onMouseOver and onMouseOut but not the onClick.

          can you please help me with an example
          See the link provided by Death Slaught. If you've got an example of onmouseout and onmouseover, onclick is pretty much the same.

          Comment

          • goal2007
            New Member
            • Jul 2007
            • 25

            #6
            Image Swaping Problem (please help)

            Here is what i have:

            [HTML]<script type="text/javascript">
            function swap()
            {
            document.getEle mentById("b1"). src ="images/buttons/Buy2.gif"

            }
            </script>


            <a href="Buy.aspx" target="_blank" >
            <img border="0" alt=" " src="images/buttons/Buy.gif" name="b1" onclick="swap() " /></a>
            [/HTML]


            The code works fine but there is a problem: when i click on the button "Buy" it will open a new window with the image Buy2.gif. I want the image to change to Buy2.gif and stay at the same window. So i changed the target = "_self" but the problem the page will always go back the imae Buy.aspx which is the default one

            your input will be appreciated!
            Thanks
            Last edited by gits; Nov 24 '07, 07:12 PM. Reason: added code tags

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              You have:
              [code=javascript]
              getElementById( 'b1')
              [/code]
              [code=html]
              <img NAME="b1" src="sda.jpg" />
              [/code]
              See how you have NAME specified as 'b1' and not ID
              change it to this
              [code=html]
              <img id="b1" border="0" alt=" " src="images/buttons/Buy.gif" name="b1" onclick="swap() " />
              [/code]

              Oh wait, i misread your problem!

              Sorry..

              For the problem you have, all i can think of is with the onlick() function, set a cookie in that? And then read it to see which image should be displayed?

              For the <a href="someplace .php" target="_self">
              just leave the target="_self" out. It isn't neccesary.

              Comment

              • goal2007
                New Member
                • Jul 2007
                • 25

                #8
                Thank you for your input. I did what you suggested I took the target="_self" out and still not working. what happened is the image changed to Buy2.gif for one second then it went back to the Buy.gif image. it only works if i do target="_blank" but it will open it in a new window which is not what i want to do.

                I think the problem is with page post back. this script is in a master page that is called by Buy.aspx page so when i click on the button it will change the image to buy2.gif, but when it loads again the image go back the buy.gif which is the default one?
                any thoughts!

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  You will need to set a cookie to 'remember' which image is to be displayed.

                  See this article or this tutorial.

                  Comment

                  • Death Slaught
                    Top Contributor
                    • Aug 2007
                    • 1137

                    #10
                    You shouldn't need cookies if the image that was specified isn't supposed to go to that specific user. Useing variables is alot easier.

                    - Death

                    PS - I've got a code at my house that I did after I saw this thread, if you haven't figured it out by then I'll give it to you.

                    PSS- WOOT! 300 POST!

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      Originally posted by Death Slaught
                      You shouldn't need cookies if the image that was specified isn't supposed to go to that specific user. Useing variables is alot easier.
                      If he wants to remember that the image has changed even after the page has reloaded, he will need cookies.
                      Originally posted by Death Slaught
                      PSS- WOOT! 300 POST!
                      Congratulations !

                      Comment

                      • Death Slaught
                        Top Contributor
                        • Aug 2007
                        • 1137

                        #12
                        Originally posted by acoder
                        If he wants to remember that the image has changed even after the page has reloaded, he will need cookies.

                        Congratulations !
                        Yeah there's a few options for him, and thanks, Death

                        Comment

                        Working...