Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Nov 2004
    Location
    near the only active volcano in the continental US
    Posts
    409
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Question Object Expected error

    I had this code working at one point (a few hours ago) and have been trying to clean it up a little bit while adding a bit of dynamic content. Now, all of the sudden, I am getting an "Object Expected" at the point of body onLoad and at the point that the onMouseover/onMouseout functions are called. I made no changes to the onLoad call at all so if anyone has any ideas, I am all ears.

    Code:
    var step=1
    
    function rotateilly()
    {
    if (!document.images)
    return
    if (document.all)
    illypic.filters.blendTrans.apply()
    document.images.illypic.src=eval("illyimage"+step+".src")
    document.images.illypic.alt=eval("illyimage"+step+"alt")
    if (document.all)
    illypic.filters.blendTrans.play()
    if (step<3)
    step++
    else
    step=1
    setTimeout("rotateilly()",4000)
    }
    
    function rotateimage(whichpic,whichimage)
    {
    if (!document.images)
    return
    if (document.all)
    whichpic.filters.blendTrans.apply()
    document.images.whichpic.src=eval(whichimage+".src")
    if (document.all)
    whichpic.filters.blendTrans.play()
    }
    
    function shiftcontent(current,next)
    {
    if (!document.all)
    return
    else
    {
    document.getElementById(current).style.visibility="hidden"
    docuement.getElementById(next).style.visibility="visible"
    }
    .....
    
    <body background="newdesertbg2.jpg" topmargin="0" leftmargin="0" bgproperties="fixed" onLoad="rotateilly()">
    
    <div id="illydiv" style="position:absolute;top:0;left:0;visibility:visible">
    
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="100" rowspan="3" valign="top">
    <center>
    <img src="totmglyph.gif" id="templepic1" class="click" border="0" style="filter:blendTrans(duration=1)" alt="Enter the Temple of the Snake" onMouseover="rotateimage('templepic1','templeimage2')" onMouseout="rotateimage('templepic1','templeimage1')" onClick="shiftcontent('illydiv','templediv')">
    </td>
    <td height="425">
    <center>
    <img src="illyanaone.gif" id="illypic" border=0 style="filter:blendTrans(duration=2)" alt="The Desert Queen of Snakes">
    </center>
    </td>
    <td width="100" rowspan="3" valign="top">
    <center>
    <img src="roeglyph.gif" id="rulespic1" class="click" border="0" style="filter:blendTrans(duration=1)" alt="Things you should know before Engaging the Queen" onMouseover="rotateimage('rulespic1','rulesimage2')" onMouseout="rotateimage('rulespic1','rulesimage1')" onClick="shiftcontent('illydiv','rulesdiv')">
    </td>
    I can only assume that I might be getting Object Expected errors at the point of the onClick call as well, but since the other two calls aren't working, I cant be sure just yet. Basicly I am working to get all the content on one page and just shift it about dynamically instead of loading page after page. Is it possible that I am getting these errors because I am not defining width or height for the div elements?

  • #2
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    946
    Thanks
    0
    Thanked 129 Times in 128 Posts
    document.images.illypic.src=eval("illyimage"+step+".src")
    document.images.illypic.alt=eval("illyimage"+step+"alt")
    here you are calling th attributes of elements ID'ed or named illyimage1,illyimage2 and illyimage3

    These elements are nonexisting

    and i will suggest that you are enclosing you statements if (this_is_true) statement in curly brackets "{}" which is the right syntax. if (this_is_true){statement}

    it also makes it easier for you to locate each if-call and give you the possibility to nest if-calls

  • #3
    Regular Coder
    Join Date
    Nov 2004
    Location
    near the only active volcano in the continental US
    Posts
    409
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Those elements are identified earlier in the code, just didn't include them because they didn't strike me as being part of the problem. The only thing that changed for them at all was the addition of the div element in the body of the document. The original code looked thusly;

    Code:
    <script type="text/javascript">
    <!--
    
    //preload images
    
    var illyimage1=new Image()
    illyimage1.src="illyanaone.gif"
    var illyimage1alt="The Desert Queen of Snakes"
    var illyimage2=new Image()
    illyimage2.src="illyanatwo.gif"
    var illyimage2alt="Snakes are not her only pets"
    var illyimage3=new Image()
    illyimage3.src="illyanatre.gif"
    var illyimage3alt="The consumation of her love for the Desert King"
    var templeimage1=new Image
    templeimage1.src="totmglyph.gif"
    var templeimage2=new Image
    templeimage2.src="totmnonglyph.gif"
    var queenimage1=new Image
    queenimage1.src="momglyph.gif"
    var queenimage2=new Image
    queenimage2.src="momnonglyph.gif"
    var rulesimage1=new Image
    rulesimage1.src="roeglyph.gif"
    var rulesimage2=new Image
    rulesimage2.src="roenonglyph.gif"
    ((this was cut to save space in the original post))
    
    
    var step=1
    
    function rotateilly()
    {
    if (!document.images)
    return
    //If the browser is IE 4.x
    if (document.all)
    illypic.filters.blendTrans.apply()
    document.images.illypic.src=eval("illyimage"+step+".src")
    document.images.illypic.alt=eval("illyimage"+step+"alt")
    //If the browser is IE 4.x
    if (document.all)
    illypic.filters.blendTrans.play()
    if (step<3)
    step++
    else
    step=1
    setTimeout("rotateilly()",4000)
    }
    
    .....
    
    <img src="illyanaone.gif" id="illypic" border=0 style="filter:blendTrans(duration=2)" alt="The Desert Queen of Snakes">
    As I stated in the original post, the code worked fine and did not start to give me any errors until I tried to enclose the img src in a div element. It is also the same situation with the imageshift function that works off the mouseover and mouseout. As for the "if" calls, I know the proper syntax would be to include the code that follows it in brackets, but there is no absolute need for them in this script since it is only one line of code attached to each "if" call. Once I start working on crossbrowser compatibility and have to start doing some nesting and "else" calls, the brackets will most certainly find their way into the code. Thanks for the suggestion though.

  • #4
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    946
    Thanks
    0
    Thanked 129 Times in 128 Posts
    the problem is this line:
    document.images.whichpic.src=eval(whichimage+".src")
    it should be:

    Code:
    eval('document.images.'+whichpic+'.src=eval(whichimage+".src")')
    your script "thought" it should apply to an image named "whichpic" ,and not the value of whichpic;
    Last edited by Lerura; 10-17-2005 at 08:59 PM.

  • #5
    Regular Coder
    Join Date
    Nov 2004
    Location
    near the only active volcano in the continental US
    Posts
    409
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Yep, you're right. Cant believe I missed that. Still doesnt explain why the "rotateilly" function is returning and Object expected error though and that is the one that is really irritating me since it worked just fine until a few hours ago. lol.

  • #6
    Regular Coder
    Join Date
    Nov 2004
    Location
    near the only active volcano in the continental US
    Posts
    409
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Okay, I am going back to the basics here. This was the original code as it worked early this morning with the blend transition playing just fine. Now, however, I am getting an Object Expected error that wasn't there before.

    Code:
    <script type="text/javascript">
    <!--
    
    //preload images
    
    var illyimage1=new Image()
    illyimage1.src="illyanaone.gif"
    var illyimage1alt="The Desert Queen of Snakes"
    var illyimage2=new Image()
    illyimage2.src="illyanatwo.gif"
    var illyimage2alt="Snakes are not her only pets"
    var illyimage3=new Image()
    illyimage3.src="illyanatre.gif"
    var illyimage3alt="The consumation of her love for the Desert King"
    var templeimage1=new Image
    templeimage1.src="totmglyph.gif"
    var templeimage2=new Image
    templeimage2.src="totmnonglyph.gif"
    var queenimage1=new Image
    queenimage1.src="momglyph.gif"
    var queenimage2=new Image
    queenimage2.src="momnonglyph.gif"
    var rulesimage1=new Image
    rulesimage1.src="roeglyph.gif"
    var rulesimage2=new Image
    rulesimage2.src="roenonglyph.gif"
    
    var step=1
    
    function rotateilly()
    {
    if (!document.images) {return}
    //If the browser is IE 4.x
    if (document.all) {illypic.filters.blendTrans.apply()}
    document.images.illypic.src=eval("illyimage"+step+".src")
    document.images.illypic.alt=eval("illyimage"+step+"alt")
    //If the browser is IE 4.x
    if (document.all) {illypic.filters.blendTrans.play()}
    if (step<3) {step++}
    else {step=1}
    setTimeout("rotateilly()",4000)
    }
    
    .....
    
    </script>
    
    </head>
    
    <body background="newdesertbg2.jpg" topmargin="0" leftmargin="0" bgproperties="fixed" onLoad="rotateilly()">
    
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="100" rowspan="3" valign="top">
    <center>
    <!--linkage goes here-->
    </center>
    </td>
    <td height="425">
    <center>
    <img src="illyanaone.gif" id="illypic" border=0 style="filter:blendTrans(duration=2)" alt="The Desert Queen of Snakes">
    </center>
    </td>
    It makes no sense to me why this isn't working now as opposed to how it was working earlier, so if a fresh set of eyes sees anything, please point it out to me as I am now at a complete loss. The function call name is the same as the function name itself, the IDs match up, but now, no blend or even any change in the image at all.

  • #7
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's probably something stupid that has absolutely nothing to do with where the error is being reported...

    I had a similar error once where I forgot the final curly-brace '}' for one of my functions and from that point on, the script didn't recognize any other functions (hence all of the other functions were deemed as missing objects!). However the line that the error gave was well below where the actual error occurred.

    I wasn't able to see anything wrong in the code in your last post, however I noticed you cut out some of the code (......) so the problem might be in there somewhere. Check to make sure all code blocks have both {curly-braces}, arrays have both [square brackets], conditions etc. have both (parentheses), text have both "quotes", etc. These are usually where these simple errors can occur; it becomes very easy to miss one of the aforementioned group-punctuation symbols -- especially the last ones -- and especially when blocks of code get several layers deep in nested loops and if statements...

    Also check to make sure your images are located in the same directory as your code. I doubt that this would be the case, since you had it working before and I don't think you would have moved either the code or the picture in the meantime, but still is worth a shot....

    One last thing I noticed... some of your 'new Image()' calls lacked ()'s. I'm not sure if this would make a difference. I've always included them in constructors and I'm not sure if js is smart enough to recognize calls to constructors without the param list....
    Last edited by Pyth007; 10-19-2005 at 02:43 PM.

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    document.all doesn't test if the browser is IE4. document.all is recognised by more recent versions of IE as well as many versions of Opera. Opera does not support the transitions. Test illypic.filters instead.

    Instead of eval("illyimage"+step+".src") use window['illyimage'+step].src instead as directly referencing the field via the windows array is a lot more efficient than using eval.

    Try adding name="illypic" to the image tag. document.images uses the name and not the id.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    As felgall pointed out, don't use eval as it is inefficient. Use the window object and square bracket notation. See my sig for more info of square bracket notation.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #10
    Regular Coder
    Join Date
    Nov 2004
    Location
    near the only active volcano in the continental US
    Posts
    409
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Eh. . . actually, I got this page up and running just fine a few days ago and posted that somewhere. Think it might have gotten burried in the mix. Thanks for the suggestions though, will take a look at making a few changes if I get reports of errors from my visitors.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •