Reply
Change image onclick.
Old 10-20-2009, 01:56 PM Change image onclick.
Skilled Talker

Posts: 64
Trades: 0
Hi guys,
I currently have a function that gets called when someone clicks a link.


<a onclick="javascript:changestatus(1);" href="#"><b>Go Online</b></a> <img id="changestatus" src="Images/icons/flag_red.png">

What kind of javascript do i need to add to my function changestatus that would change the image when the link is clicked.

I want to change the image to flag_yellow.png when the link above is clicked.

I would assume it would be summat like.
document.changestatus.src="Images/icons/flag_yellow.png"

But nothing happens?

Any ideas?

Thanks
G
__________________
Talk to your visitors in realtime.
Live realtime support chat - www.IMsupporting.com
lynxus is online now
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
When You Register, These Ads Go Away!
Old 10-20-2009, 01:58 PM Re: Change image onclick.
chrishirst's Avatar
Super Moderator

Posts: 22,237
Location: Blackpool. UK
Trades: 0
add a name attribute of "changestatus"
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-20-2009, 02:04 PM Re: Change image onclick.
Skilled Talker

Posts: 64
Trades: 0
Ah ha that works.

Would i be better off using the GetElementById if i name something by id?
ie:
document.GetElementById("somename").src="blaa";

Rather than what ive done with
document.somename.src?

Am I using an outdated method?
Ive been using JS for years on and off so i feel that i may sometimes still be doing things wrong "just to get it working"




Thanks
-G
__________________
Talk to your visitors in realtime.
Live realtime support chat - www.IMsupporting.com
lynxus is online now
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 10-20-2009, 02:21 PM Re: Change image onclick.
chrishirst's Avatar
Super Moderator

Posts: 22,237
Location: Blackpool. UK
Trades: 0
either method is fine. getElementById() is now officially part of the W3c DOM spec so is "acceptable" to use, and you won't have the "DOM Police" harrassing you.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-20-2009, 02:41 PM Re: Change image onclick.
Skilled Talker

Posts: 64
Trades: 0
Hahah DOM Police " i havent ran into them yet lol "

Thanks for your help.

All working perfectly.
__________________
Talk to your visitors in realtime.
Live realtime support chat - www.IMsupporting.com
lynxus is online now
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Reply     « Reply to Change image onclick.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.12194 seconds with 13 queries