JavaScript onmouseover problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thehappyappy
    New Member
    • Jul 2007
    • 7

    JavaScript onmouseover problem

    I've come across a snippet of JavaScript that rotates images randomly. I've tried to modify it so that when I rollover it a mouse over image is shown as well as have a link to another page, but Im not to sure what I'm doing.

    The original code was:

    [CODE=javascript] random_num = (Math.round(Mat h.random()*9));
    document.write( "<img src='_random/image_" + random_num + ".jpg' width='91' height='113' hspace='0' vspace='0' border='0'><br />" );[/CODE]

    I've modified it to:

    [CODE=javascript] random_num = (Math.round(Mat h.random()*9));
    document.write( "<img src='_random/image_" + random_num + ".jpg'
    width='91' height='113' hspace='0' vspace='0' border='0' </br>
    onmouseover=\"t his.src='_rando m/image_over_" + random_num + ".jpg'\"</br>" );[/CODE]

    but then nothing is showing at all. Also I have no idea how to add links so that a different link is active depending on which image is visible

    Thanks
    Last edited by acoder; Sep 10 '07, 09:59 AM. Reason: Added language to code tag
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Get rid of the </br> on line 3 and just before the line break on line 4, close the img tag:[CODE=javascript]onmouseover=\"t his.src='_rando m/image_over_" + random_num + ".jpg'\">[/CODE]

    Comment

    Working...