Solved

Change image on click

Posted on 2009-04-06
4
689 Views
Last Modified: 2013-12-24
need to change this image on click this is not a form its simply an image that gets clcked for navigation.

Based on what i see above this is the part i put in header.

<script language = "javascript">
this.src='images/owners_small.gif';
</script>


This is code:


<p align="center"><img src="<cfoutput>#imagepath#</cfoutput>/signuptoday.gif" width="183" height="41" border="0" vspace="8" id = "affiliate" value = "Condo Affiliate: Fill out the form and you will be contacted soon." onclick="(this.src != 'images/owner_small.gif') "></p>

Open in new window

0
Comment
Question by:LeadCo
4 Comments
 
LVL 3

Assisted Solution

by:kingsob
kingsob earned 100 total points
ID: 24084109
here we go
<html>
  <head>
  </head>
  <body>
    <img src="1.png" onclick="this.src='2.png';"/>
  </body>
</html>

Open in new window

0
 
LVL 27

Accepted Solution

by:
azadisaryev earned 300 total points
ID: 24084231
no need for anything in the HEAD.
the below will change the image only if it is NOT already images/owners-small.gif

<p align="center"><img src="<cfoutput>#imagepath#</cfoutput>/signuptoday.gif" width="183" height="41" border="0" vspace="8" id = "affiliate" value = "Condo Affiliate: Fill out the form and you will be contacted soon." onclick="(this.src != 'images/owner_small.gif') this.src='images/owners_small.gif';"></p>

the js inside onclick event checks if the src of this image is 'images/owners_small.gif, and if it is not changes it to 'images/owners_small.gif'.

btw, there is no VALUE attribute for <img> tag. but there IS alt attribute, which you should always specify.

Azadi
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 100 total points
ID: 24084434
I do not see the point in changing the image unless you do something else when clicking

<p align="center">
  <img src="<cfoutput>#imagepath#</cfoutput>/signuptoday.gif" 
  width="183" height="41" border="0" vspace="8" id = "affiliate" 
  value = "Condo Affiliate: Fill out the form and you will be contacted soon." 
  onclick="(this.src = '<cfoutput>#imagepath#</cfoutput>/owner_small.gif') ">
</p>

Open in new window

0
 

Author Closing Comment

by:LeadCo
ID: 31567363
Thanks Guys!    to mplnqjan: The reason for hiding the image was because it is a naviagation image and when the ajax shows new content it is not neccessarry.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question