Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Change image onclick.
Old 10-20-2009, 01:56 PM Change image onclick.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,615
Location: UK
Trades: 1
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
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 10-20-2009, 01:58 PM Re: Change image onclick.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,515
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
add a name attribute of "changestatus"
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-20-2009, 02:04 PM Re: Change image onclick.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,615
Location: UK
Trades: 1
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
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 10-20-2009, 02:21 PM Re: Change image onclick.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,515
Name: Chris Hirst
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-20-2009, 02:41 PM Re: Change image onclick.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,615
Location: UK
Trades: 1
Hahah DOM Police " i havent ran into them yet lol "

Thanks for your help.

All working perfectly.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
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.15166 seconds with 12 queries