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 5 of 5
  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

    Object expected error, but why?

    Okay, here is the code. . . I don't understand why it is giving me an Object Expected error at the body onload statement. Am I just being braindead and missing something obvious or has something changed yet again and left me in its wake? Anyways, if one of you would be so kind as to explain why I am getting this error, I would appreciate it much.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
    
    <html lang=en-us>
    
    <head>
    
    <title>
    Some Title Here
    </title>
    
    <style type="text/css">
    <!--
    
    .click {
    cursor: pointer;
    cursor: hand;
    }
    
    .imgfader {
    position: absolute;
    top: 7;
    left: 100;
    height: 425;
    width: 820;
    visibility: visible;
    filter: alpha(opacity=10);
    -moz-opacity: 10;
    }
    
    -->
    </style>
    
    <script type="text/javascript" carset="ISO-8859-1">
    <!--
    var allimgs=new Array("firstpicshere.jpg" . . . "lastpichere.jpg")
    var imgload=new Array()
    
    for (pl=0;pl<allimgs.length;pl++)
    {
    	imgload[pl]=new Image()
    	imgload[pl].src=allimgs[pl]
    }
    
    var whichfade=new Array("illypic1","illypic2","illypic3")
    
    function initialview()
    {
    document.getElementById(whichfade[1]).style.filter= "alpha(opacity=100)"
    document.getElementById(whichfade[1]).style.-moz-opacity= "0"
    document.getElementById(whichfade[2]).style.filter= "alpha(opacity=100)"
    document.getElementById(whichfade[2]).style.-moz-opacity= "0"
    }
    
    -->
    </script>
    
    </head>
    
    <body background="newdesertbg2.jpg" topmargin="0" leftmargin="0" bgproperties="fixed" onLoad="initialview()">
    .
    .
    .
    </html>

  • #2
    New to the CF scene
    Join Date
    Sep 2005
    Location
    Michigan
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I may be mistaken, but I believe that rather than -moz-opacity, when calling it with JS rather than CSS, it is MozOpacity.

  • #3
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    You need to check whch style attributed is supported by the user's browser otherwise it will always error out in every browser.

    This should work for you:
    Code:
    function initialview() {
    	for(var i=0; imgload[i]; i++) {
    		if(imgload[i].style.MozOpacity) {
    			imgload[i].style.MozOpacity = 0;
    		} else {
    			imgload[i].style.filters.alpha.opacity = 0;
    		}
    	}
    }
    Hope this helps.

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    That code will still give an error in browsers that don't support either opacity method such as Opera.
    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.

  • #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
    I realized that I may not have posted enough of the coding to clearly identify my problem. With that in mind, I trimmed things back a bit and am just working with the Opacity feature as it applies to IE at this point. When I define the class, everything does just what it is supposed to. However, later, when I go to turn the opacity down on two of the three objects, it just doesnt seem to work at all. Here is the full coding up to the point that it should turn the opacity down . . .

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
    
    <html lang=en-us>
    
    <head>
    
    <title>
    Mistress of the Maji : The Desert Queen of Snakes : Illyana Nightshade
    </title>
    
    <style type="text/css">
    <!--
    
    .imgfader {
    position: absolute;
    top: 7;
    left: 100;
    height: 425;
    width: 820;
    visibility: visible;
    filter: alpha(opacity=100);
    }
    
    -->
    </style>
    This part works just fine when it is applied to the div elements later on.

    Code:
    <script type="text/javascript" charset="ISO-8859-1">
    <!--
    var allimgs=new Array("desertbg2.jpg","illyanaone.jpg","illyanatwo.jpg","illyanatre.jpg","temple.gif","momglyph.gif","momnonglyph.gif","roeglyph.gif","roenonglyph.gif","totmglyph.gif","totmnonglyph.gif")
    var imgload=new Array()
    
    for (pl=0;pl<allimgs.length;pl++)
    {
    	imgload[pl]=new Image()
    	imgload[pl].src=allimgs[pl]
    }
    
    -->
    </script>
    As far as I can tell, this part is also working just fine though I haven't loaded it onto my server yet, so will have to double check it once I do.

    Code:
    </head>
    
    <body background="newdesertbg2.jpg" topmargin="0" leftmargin="0" bgproperties="fixed">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="100" rowspan="3" valign="top">
    <center>
    <img src="test33.gif">
    </td>
    <td height="425">
    <div id="illypic1" class="imgfader">
    <table width="820" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td height="425">
    <center>
    <img src="illyanaone.jpg" alt="Desert Queen of the Snakes">
    </center>
    </td>
    </tr>
    </table>
    </div>
    <div id="illypic2" class="imgfader">
    <table width="820" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td height="425">
    <center>
    <img src="illyanatwo.jpg" alt="Snakes aren't her only pets.">
    </center>
    </td>
    </tr>
    </table>
    </div>
    <div id="illypic3" class="imgfader">
    <table width="820" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td height="425">
    <center>
    <img src="illyanatre.jpg" alt="The Consumation of her love for the Desert King.">
    </center>
    </td>
    </tr>
    </table>
    </div>
    </td>
    
    <script type="text/javascript" charset="ISO-8859-1">
    <!--
    function initializeview()
    {
    document.getElementById("illypic2").style.filters.alpha.opacity=1
    document.getElementById("illypic3").style.filters.alpha.opacity=1
    }
    initializeview()
    -->
    </script>
    Unless I am just terribly missing something obvious, the highlighted function should dial the opacity of the elements in question down to nothing more than the barest hint of a ghost image. However, it does nothing of the sort and I don't understand why. I have seen similar scripts on other web sites and they seem to have no problem what so ever, but for some reason it is simply not working for me. If anyone has any clue, I am all ears. . .

    GW


  •  

    Posting Permissions

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