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 "scr" setting

Status
Not open for further replies.

VJar

Programmer
Aug 3, 2002
18
UA
I have object "img":

<img id=&quot;img1&quot; alt=&quot;&quot; width=&quot;100&quot; height=&quot;100&quot; border=&quot;0&quot;>

Can I in JavaScript set the path to the file (src=&quot;image.jpg&quot;),
from where this image will load, when I have image &quot;id&quot;?
 
To get the image:
document.getElementById('imgid').scr = &quot;path/&quot; + &quot;filename.&quot; + &quot;extention (could be jpg or gif)&quot;

So if the image has allready got a filename as the src and you want to set the path you can do somehting like this:

document.getElementById('imgid').scr = &quot;path/&quot; + document.getElementById('imgid').scr
 
Of course. One of the possible things is image rollover existing for years.
This is one of the best rollover scripts I ever saw (small and efficient):

function change(imgNumb,imgFile) {
if (document.images)
document.images
.src = eval(imgFile + '.src');
}

<a href=&quot;&quot; onmouseover=change('n1','img4'); onmouseout=change('n1','img3');><img src=&quot;&quot; name=&quot;n1&quot; ...></a>

where img3 and img4 are defined in the script body:
img3=new Image();
img3.src=&quot;images/some.gif&quot;;
img4=new Image();
img4.src=&quot;images/other.gif&quot;;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top