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 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    27
    Thanks
    8
    Thanked 0 Times in 0 Posts

    I can’t pass properties to function

    Hi all! I can`t pass properties to function. It should be something easy, but there is no way. I’ve lost the whole day trying to do it, but in vain.

    The error is “Esperaba un objeto“ (“an object expected”)


    Could anyone help me please?


    Here is my code:




    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
    <title>Ball</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css" media="screen">
    html, body { height:100%; background-color: #00ffaa;}
    body { margin:0; padding:0; overflow:hidden; }
    #flashContent { width:100%; height:100%; }
    </style>
    
    
    <title>Showing and Hiding Elements with JavaScript</title>
    <script type="text/javascript" src="EnvVars.js">
    function changeVisibility(TR){
    if (document.getElementById('flashContent2').style.visibility=="hidden") {
    document.getElementById('flashContent2').style.visibility = "visible";
    } else {
    document.getElementById('flashContent2').style.visibility = "hidden";
    }
    }
    
    </script>
    
    </head>
    <body>
    <div id="flashContent2" style="position: absolute; top: 210px; left: 260px; ">
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100" height="50" id="Ball" align="middle">
    <param name="movie" value="Ball.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffffff" />
    <param name="play" value="true" />
    <param name="loop" value="true" />
    <param name="wmode" value="transparent" />
    <param name="scale" value="showall" />
    <param name="menu" value="true" />
    <param name="devicefont" value="false" />
    <param name="salign" value="" />
    <param name="allowScriptAccess" value="sameDomain" />
    
    <a href="http://www.adobe.com/go/getflash">
    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
    </a>
    
    </object>
    
    </object>
    </div>
    
    <form>
    <h2>visibility</h2>
    <input type="button" onclick="changeVisibility('flashContent2')" value="Doesn't work">
    
    </form>
    
    
    
    
    
    
    
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    967
    Thanks
    19
    Thanked 211 Times in 209 Posts
    This may not be a complete solution but,
    it is a necessary change . Make it like
    this then ask more questions ....

    <script type="text/javascript" src="EnvVars.js"></script>
    <script type="text/javascript">
    function changeVisibility(TR){

  • Users who have thanked DaveyErwin for this post:

    Drunklord (09-07-2011)

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    I notice also that you state the div id within the function and also pass it as a parameter.

    If your going to pass the id to the function try

    function changeVisibility(ID){
    if (document.getElementById(ID).style.visibility=="hidden") {
    document.getElementById(ID).style.visibility = "visible";
    } else {
    document.getElementById(ID).style.visibility = "hidden";
    }
    }
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Explanation:

    When you use src="xxx" to specify an external JS file, then any *CODE* you put between <script> and </script> will *ONLY* be executed if the external JS file fails to load.

    In other words, the code becomes "just in case" code.

    Davey is showing you that, by putting your code in a *SEPARATE* set of <script>...</script> tags it will run regardless of the external code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Drunklord (09-07-2011)

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Or even simpler:
    Code:
    function changeVisibility(ID){
        var div = document.getElementById(ID);
        div.style.visibility = div.style.visibility == "visible" ? "hidden" : "visible";
    }
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Drunklord (09-07-2011)

  • #6
    New Coder
    Join Date
    Sep 2011
    Posts
    27
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thank you all, now it works


  •  

    Posting Permissions

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