By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,928 Members | 1,585 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,928 IT Pros & Developers. It's quick & easy.

html image swapping problem

P: 25
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
Nov 13 '07 #1
Share this Question
Share on Google+
11 Replies


drhowarddrfine
Expert 5K+
P: 7,435
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.
Nov 13 '07 #2

gits
Expert Mod 5K+
P: 5,390
hi ...

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

kind regards
Nov 13 '07 #3

Death Slaught
100+
P: 1,137
"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
Nov 13 '07 #4

acoder
Expert Mod 15k+
P: 16,027
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.
Nov 14 '07 #5

P: 25
Here is what i have:

[HTML]<script type="text/javascript">
function swap()
{
document.getElementById("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
Nov 24 '07 #6

Markus
Expert 5K+
P: 6,050
You have:
Expand|Select|Wrap|Line Numbers
  1. getElementById('b1')
  2.  
Expand|Select|Wrap|Line Numbers
  1. <img NAME="b1" src="sda.jpg" />
  2.  
See how you have NAME specified as 'b1' and not ID
change it to this
Expand|Select|Wrap|Line Numbers
  1. <img id="b1" border="0" alt=" " src="images/buttons/Buy.gif" name="b1" onclick="swap()" />
  2.  
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.
Nov 24 '07 #7

P: 25
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!
Nov 24 '07 #8

acoder
Expert Mod 15k+
P: 16,027
You will need to set a cookie to 'remember' which image is to be displayed.

See this article or this tutorial.
Nov 26 '07 #9

Death Slaught
100+
P: 1,137
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!
Nov 26 '07 #10

acoder
Expert Mod 15k+
P: 16,027
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.
PSS- WOOT! 300 POST!
Congratulations!
Nov 26 '07 #11

Death Slaught
100+
P: 1,137
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
Nov 26 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.