#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    4
    Rep Power
    0
    I receive an error everytime I try to use this rollover.(Error: document.images[...] is not an object). I am hoping someone can tell me what is wrong with my code. Or that I forgot to declare something.

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function preload(ImgVar,ImgBase)
    {
    if (document.images)
    {
    eval(ImgVar+' = new Image()');
    eval(ImgVar+'.src = "'+ImgBase+'"');
    }
    }

    var PreloadFlag=false;

    function preloadAll()
    {
    if (document.images)
    {
    preload('n1','images/4csoff.gif');

    preload('m1','images/4cson.gif');

    preload('c1','images/4csclk.gif');


    PreloadFlag = true;

    }
    }

    function onOver(bindex)

    {
    if (PreloadFlag==true&&bindex!=ButtonClicked)

    {
    var temp='btn'+bindex; document.images[temp].src=eval('m'+bindex).src;

    }
    }

    var ButtonClicked=1000;


    function onClick(bindex) {
    if (PreloadFlag==true&&bindex!=ButtonClicked) {

    if (ButtonClicked!=1000) {

    var temp='btn'+ButtonClicked; document.images[temp].src=eval('n'+ButtonClicked).src;

    }
    var temp='btn'+bindex; document.images[temp].src=eval('c'+bindex).src;

    ButtonClicked=bindex

    }
    }

    function onOut(bindex) {

    if (PreloadFlag==true&&bindex!=ButtonClicked) {

    var temp='btn'+bindex; document.images[temp].src=eval('n'+bindex).src;

    }
    }

    //-->
    </SCRIPT>

    <!-- End Preload Script -->

    </HEAD>

    <BODY background="bluebg.gif" TEXT="#000000" LINK="#0000FF" VLINK="#800080" onload="preloadAll();">

    <table>
    <tr>
    <td><a href="4cs.htm"
    onMouseOver="onOver(0); return true"
    onMouseOut="onOut(0); return true"
    onClick="onClick(0)" target="body"> <img name="btn1" src="images/4csoff.gif" border=0></a></td></tr>

    Thank You
    amberm99


    [This message has been edited by amberm99 (edited May 18, 2000).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Posts
    84
    Rep Power
    16
    That seems to be an awful lot of code for just an image rollover. Try something like this:

    <html>
    <head>
    <title>Simple Image Rollover</title>
    <script language="Javascript">
    <!--//
    // This statement detects if the browser supports the image object
    if (document.images) {

    //This section Preloads the images to be used for the rollover
    //You can also add the width and height of the images inside the parentheses seperated by a comma
    imageOut = new Image();
    imageOver = new Image();

    //This section specifies the location or url of the images to be used
    imageOut.src = "image1.jpg"
    imageOver.src = "image2.jpg"
    }
    //-->
    </script>
    </head>
    <body>

    <a href="somewhere.html" onMouseover="document.rollover.src=imageOver.src" onMouseout="document.rollover.src=imageOut.src">
    <img src="image1.jpg" border="0" name="rollover"></a>

    <!-- To produce the rollover effect you will use the onMouseove/onMouseout event
    handlers. You must give your image tag an id. To do that you will just add the
    name attribute(ie. <img name="myimage"> ) inside of the image tag. Then
    refer to the image you would use "document" which refers to the page that the
    image tag resides in followed by a period and the you type the name you gave
    to the image with the name attribute and then another period and type "src=".
    The src is what you assigned to the location of the image to be changed back
    in the script(ie. image1.src). If you wanted to change an image located in
    another frame then the statement in your onMouse event handler would look
    something like this:
    onMouseover="parent.framename.document.rollover.src=image2.src"
    In this case you refer to the parent window and the the framename and then
    continue the statement as usual. One final note- In the HREF if you want an
    actual link to another page then just put the link in there. If you do not want
    to link to another page then you can just use the following to disable the
    HREF portion: HREF="javascript:void(null);"
    -->
    </body>
    </html>

    Spookster
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    4
    Rep Power
    0

    Thank you for your response Spookster. What I was actually trying to get was a rollover effect that when you clicked on the button it would show a third image to show which page you are on. I am using frames and I didnt want to just reload the page with a different image. I wanted to use the onclick event. Do you know how I would go about doing this with frames?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Posts
    84
    Rep Power
    16
    I explained how to change an image in another frame in the description. If you have more questions you can get hold of me at my forum where I moderate the DHTML section at:

    WSAbstract Web Design Forum

    Spookster

Similar Threads

  1. JavaScript XML Access Denied error
    By bman in forum JavaScript Development
    Replies: 5
    Last Post: April 6th, 2006, 05:16 AM
  2. Can't find javascript error
    By DorkRawk in forum JavaScript Development
    Replies: 2
    Last Post: September 12th, 2003, 02:22 PM
  3. odd error with javascript mailto function
    By Leigh O in forum JavaScript Development
    Replies: 0
    Last Post: May 22nd, 2003, 01:13 PM
  4. Problem compiling in Cygwin
    By dtm78 in forum C Programming
    Replies: 1
    Last Post: February 24th, 2003, 06:06 AM
  5. JavaScript Error on IE
    By spmfreeman in forum JavaScript Development
    Replies: 0
    Last Post: July 20th, 2002, 03:12 PM

IMN logo majestic logo threadwatch logo seochat tools logo