SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Thread: What's wrong?

  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy What's wrong?

    Dear everyone,

    After a bit of experimentation, I decided to write a sidebar script that would collapse and expand itself... just like SitePoint's. This is the result:

    Code:
    function hide()
    {
    document.getelementbyid("showhide").innerhtml=
    "
    <a class=\"link\" href=""\"javascript:show()\">
    <div>S</div>
    <div>h</div>
    <div>o</div>
    <div>w</div>
    </a>
    "
    ;
    document.getelementbyid("sidebarimage").classname="abnormalsidebarimage";
    document.getelementbyid("sidebarcontent").classname="abnormalsidebarcontent";
    document.getelementbyid("contentframe").classname="abnormalcontentframe";
    document.getelementbyid("showhide").classname="abnormalshowhide";
    }
    function show()
    {
    document.getelementbyid("showhide").innerhtml=
    "
    <a class=\"link\" href=""\"javascript:show()\">
    <div>H</div>
    <div>i</div>
    <div>d</div>
    <div>e</div>
    </a>
    "
    ;
    document.getelementbyid("sidebarimage").classname="normalsidebarimage";
    document.getelementbyid("sidebarcontent").classname="normalsidebarcontent";
    document.getelementbyid("contentframe").classname="normalcontentframe";
    document.getelementbyid("showhide").classname="anormalshowhide";
    }
    However, when the script is called (via "javascript:hide()" or "javascript:show()" in the anchor tag), I get a debug error stating "object expected." What's wrong?

    Compuwhiz7

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    javascript objects are case-sensitive.

    getElementById
    className
    innerHTML

    This is called camel casing (or, camelCasing ) because it gives the text a humped appearance
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    I modified the casing of the objects listed by Beetle, but I'm still getting the error that says "object expected." Any further ideas?

    Compuwhiz7

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    Hello? I'm dying to get some help here...

    Compuwhiz7

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    show us the HTML that goes with this scripting
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Javascript doesn't support multiline variable definitions I don't believe.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  7. #7
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's true - I looked right past that. This "line"
    Code:
    document.getelementbyid("showhide" ).innerhtml=
    "
    <a class=\"link\" href=""\"java script:show()\">
    <div>S</div>
    <div>h</div>
    <div>o</div>
    <div>w</div>
    </a>
    "
    ;
    needs to be changed to
    Code:
    document.getElementById( "showhide" ).innerHTML = 
    "<a class=\"link\" href=""\"java script:show()\">" +
    "<div>S</div>" +
    "<div>h</div>" +
    "<div>o</div>" +
    "<div>w</div>" +
    "</a>";
    But I'm confused, because this would throw an "Unterminated string constani" error, not "Object expected".

    We just don't see enough of the code/HTML here to find the source of the problem, I think.
    Last edited by beetle; Jun 22, 2003 at 13:29.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    Okay. Just so we're all on the same page here, I'll list all of the applicable code. This is my HTML code:
    Code:
    <div class="normalshowhide" id="showhide">
    <a class="link" href="java script:hide();">
    <div>H</div>
    <div>i</div>
    <div>d</div>
    <div>e</div>
    </a>
    </div>
    The JavaScript code is:

    Code:
    function hide()
    {
    document.getElementById("showhide" ).innerHTML=
    "<a class=\"link\" href=""\"java script:show();\">"+
    "<div>S</div>"+
    "<div>h</div>"+
    "<div>o</div>"+
    "<div>w</div>"+
    "</a>"
    ;
    document.getElementById("sidebarimage" ).className="abnormalsidebarimage";
    document.getElementById("sidebarcontent" ).className="abnormalsidebarcontent";
    document.getElementById("contentframe" ).className="abnormalcontentframe";
    document.getElementById("showhide" ).className="abnormalshowhide";
    }
    function show()
    {
    document.getElementById("showhide" ).innerHTML=
    "<a class=\"link\" href=""\"java script:show();\">"+
    "<div>H</div>"+
    "<div>i</div>"+
    "<div>d</div>"+
    "<div>e</div>"+
    "</a>"
    ;
    document.getElementById("sidebarimage" ).className="normalsidebarimage";
    document.getElementById("sidebarcontent" ).className="normalsidebarcontent";
    document.getElementById("contentframe" ).className="normalcontentframe";
    document.getElementById("showhide" ).className="anormalshowhide";
    }
    Incidentally, the HTML segment displayed is a file that's included in other files using ASP.NET's "Response.WriteFile();" command. Within other HTML files, the script is included using:
    Code:
    <script language="JavaScript" src="/js/showhide.js"></script>
    Thanks for your help; I think we've almost got it.

    Compuwhiz7

  9. #9
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    Never mind; I fixed it.

    Compuwhiz7

  10. #10
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rule 73, paragraph 5, subsection D of the Sitepoint User's Charter:
    Users who solve their own problems are strongly encouraged to post the solution they have found instead of simply posting "Never mind; I fixed it" (or similar) which doesn't help anyone else who may have the same problem.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  11. #11
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    Sorry, Marco. I'm actually not entirely sure what I did to fix my script, but I'll post it below.

    Code:
    function hide()
    {
    document.getElementById("showhide").innerHTML=
    "<a class=\"link\" href=""\"javascript:show();\">"+
    "<div>S</div>"+
    "<div>h</div>"+
    "<div>o</div>"+
    "<div>w</div>"+
    "</a>"
    ;
    document.getElementById("sidebarimage").className="abnormalsidebarimage";
    document.getElementById("sidebarcontent").className="abnormalsidebarcontent";
    document.getElementById("contentframe").className="abnormalcontentframe";
    document.getElementById("showhide").className="abnormalshowhide";
    }
    function show()
    {
    document.getElementById("showhide").innerHTML=
    "<a class=\"link\" href=""\"javascript:hide();\">"+
    "<div>H</div>"+
    "<div>i</div>"+
    "<div>d</div>"+
    "<div>e</div>"+
    "</a>"
    ;
    document.getElementById("sidebarimage").className="normalsidebarimage";
    document.getElementById("sidebarcontent").className="normalsidebarcontent";
    document.getElementById("contentframe").className="normalcontentframe";
    document.getElementById("showhide").className="normalshowhide";
    }
    Once, again, I apologize for my mistake.

    Compuwhiz7

  12. #12
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  13. #13
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear everyone,

    Glad to please.

    Compuwhiz7


Bookmarks

Posting Permissions

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