Image Rollover

http://stackoverflow.com/questions/10215938/why-doesnt-my-simple-javascript-rollover-work

by ryanwfiorini

HTML

<a href="index.html" onmouseover="buttondown('homebutton')"       onmouseout="buttonup('homebutton')">
  <img id='Img4Inner' name="homebutton" src='http://dummyimage.com/200x100/000000/fff&text=out' alt="" />

  </a>

JavaScript

if (document.images) {
    homebuttonup = new Image();
    homebuttonup.src = "http://dummyimage.com/200x100/000000/fff&text=out";
    homebuttondown = new Image();
    homebuttondown.src = "http://dummyimage.com/200x100/000000/fff&text=over";
}

function buttondown(buttonname) {
    if (document.images) {
        document.getElementByID("Img4Inner").src = homebuttondown.src;
    }
}

function buttonup(buttonname) {
    if (document.images) {
        document[buttonname].src = eval(buttonname + "up.src");
    }
}