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!

Image Changer

Status
Not open for further replies.

beret

Programmer
Dec 7, 1999
1
US
I am a novice programmer<br>
<br>
Could someone PLEASE help me. I want to change the picture (at least 6) by useing a multiple buttons. When I click a button (multiple on the page) the image changes. I realize this is an onClick event yet I am not sure how to call the function from my var = new Image()
 
Which function do you want to call from my var = new Image()? What you could do, it change the src field in the image variable and that will load the new image. This works in NN and I think in IE as well though I am not 100% sure of that because I don't use IE. Anyway, something like this:<br>
<br>
function changeImg(imgLocation) {<br>
myimage.src = imgLocation;<br>
}<br>
<br>
...<br>
...<br>
...<br>
<br>
&lt;img name=&quot;myimage&quot; src=&quot;...&quot;&gt;<br>
<br>
Then in your button definition, put an onClick method which calls the changeImg function with a location (URL location) of the image you want.<br>
<br>
As an optimization, you could put all the images you want to use in a &lt;div&gt; &lt;/div&gt; and make this layer invisible. This is because when NN and IE encounter the layer, they load everything in the layer the first time. Afterwards, when you change images, the images are already local, so the change it very fast.<br>
<br>
tito<br>
<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top