Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

altering picture source using javascript

Status
Not open for further replies.

gegd4xc9

Programmer
Jan 20, 2005
1
NZ
Im creating a webpage on which I have a table. one of the cells is to hold picures. I need to know how to change the picture in that cell by clicking on a button or text. I have a list of images I was to go through and show in the cell.
 
One way:

Window.document has a property called images[] that is an array of the images on a webpage. You would then be able to manipulate that image by finding it in the array and modifying its properties.

Nick Ruiz
Webmaster, DBA
 

Example:

function:
Code:
<script language="javascript"><!--

function changeImg(strSrc) {
    document.getElementById('mainImg').src = strSrc;
    return false;
}

--></script>

the html:
Code:
<table><tr>
  <td>
    <a href="image1.gif" onclick="return changeImg(this.href);">Image 1</a><br />
    <a href="image2.gif" onclick="return changeImg(this.href);">Image 2</a><br />
    <a href="image3.gif" onclick="return changeImg(this.href);">Image 3</a><br />
  </td>
  <td>
    <img src="default.gif" name="mainImg" id="mainImg" />
  </td>
</tr></table>

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top