Forum Moderators: open
I have two separate buttons created called chipinprog.jpg and chipinprogdown.jpg.
Thanks!
<a href="chipin.html"
onmouseover="buttondown('chipinprogdownbutton')"
onmouseout="buttonup('chipinprogbutton')">
<img src="chipinprog.jpg" name="chipinprogbutton" border="0" />
</a>
</STYLE>
<script language="JavaScript" type="text/javascript">
<!--
if (document.images) {
chipinprogbuttonup = new Image();
chipinprogbuttonup.src = "chipinprog.jpg" ;
chipinprogbuttondown = new Image() ;
chipinprogbuttondown.src = "chipinprogdown.jpg" ;
}
function buttondown( chipinprogbuttondown )
{
if (document.images) {
document[ chipinprogbutton ].src = eval( chipinprogbutton + "down.src" );
}
}
function buttonup ( chipinprogbutton )
{
if (document.images) {
document[ chipinprogbutton ].src = eval( chipinprogbutton + "up.src" );
}
}
// -->
</script>
<script language="JavaScript" type="text/javascript">
<!--
if (document.images) {
var chipinprogbuttonup = new Image();
chipinprogbuttonup.src = "chipinprog.jpg" ;
var chipinprogbuttondown = new Image() ;
chipinprogbuttondown.src = "chipinprogdown.jpg" ;
}
// -->
</script>
<a href="chipin.html"
onmouseover="setImage('chipinprogbutton','chipinprogdown.jpg')"
onmouseout="setImage('chipinprogbutton','chipinprog.jpg')">
<img src="chipinprog.jpg" alt="pic" id="chipinprogbutton" border="0" />
</a><script type="text/javascript">
//we don't actually need to pre-load 'chipinprog.jpg', as it is defined in an img tag already
//and will already be cached, but I am including it below in the
//imagesToPreload array just for demo
var imagesToPreload = ['chipinprog', 'chipinprogdown.jpg']; //add any other image paths in to this array that you wish to be preloaded
var preloadedImages = []; //a storage array for the 'for' loop to use below for new Image's
for (var i = 0; i < imagesToPreload.length; i++) {
preloadedImages[i] = new Image();
preloadedImages[i].src = imagesToPreload[i];
}//one function is all that is needed.
//pass images id as first parameter and the new src value as second parameter
function setImage(imgElementId,newSrc) { //use id in the image, and document.getElementById instead
document.getElementById(imgElementId).src = newSrc;
}</script>
function buttondown( chipinprogbuttondown )
{
if (document.images) {
document[ chipinprogbutton ].src = eval( chipinprogbutton + "down.src" );
}
}
eval( chipinprogbutton + "down.src" );
chipinprogbutton is undefined, perhaps chipinprogbuttondown ahould be chipinprogbutton as per buttonup() ?
as you add chipinprogbutton to a text string ( + "down.src" ) assumably it needs to be a text string ?
there is no need to eval() a text string
document[ chipinprogbutton ].src
document[ "chipinprogbutton" ].src
equiv to
document.chipinprogbutton.src
if so
document.getElementById( "chipinprogbutton" ).src is preferable
Etc