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

    Join Date
    Apr 2002
    Posts
    8
    Rep Power
    0

    Question DHTML, visibility, etc


    hi,
    i cant make the following basic DHTML work. Porpuse is, when mouse is clicked, make some part of page visible. but nothing hapenned ! except an instant note on status bar: error on page :)

    where is the error ?
    thanks for coming helps...

    ps1: both 'this.name' property and id name function calling didnt work
    ps2: i use IE 5.0 how can i see javascript errors at IE ? as in NN6.0 when "javascript: " is written in address bar

    --- HTML CODE :
    <script type="text/javascript">
    function makevisible (spanname) {
    spanname.style.visibility="visible"
    }
    </script>
    <body>
    <ul>
    <li> <a href="javascript:makevisible(this.name)" name="span_one"> html </a>
    <li> <a href="javascript:makevisible(span_two)" name="span_two"> jscript </a>
    </ul>

    <span id="span_one" style="visibility:hidden" >
    bla bla bla of html
    </span>
    <p>
    <span id="span_two" style="visibility:hidden" >
    bla bla bla of javascript
    </span>
    -----------------------------

    thnx.
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    25
    document.getElementById(spanname).style.visiblity = "visible"

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

    Join Date
    Apr 2002
    Posts
    8
    Rep Power
    0
    binky: it didnt work, neither
    but strange, it must have run ...

    any other suggestion or alternative code ?
  6. #4
  7. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    25
    In IE you can double click the yellow logo that appears at the bottom left if there's an error. Or go into internet options and switch on 'allways report javascript errors' or something to that effect.

    Okay, what I can gather is this:

    Using:
    document.getElementById(spanname).style.visibility = "visible"

    <a href="javascript: makevisible(this.name)" name="span_one"> html </a> -- will not work because IE sees the 'name' attribute as the 'id' attribute so it gets confused, stupid eh?

    So, using:
    document.getElementById(spanname).style.visibility = "visible"

    and:
    <a href="javascript: makevisible('span_two')"> jscript </a>

    will work, notice the quotation marks though around the parameter being passed, and the lack of the 'name' attribute.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    14
    ...will not work because IE sees the 'name' attribute as the 'id' attribute so it gets confused, stupid eh?
    Somebody's confused (what a shock).

    AnthemisCretica (gotta look that up) -

    Any element's id or name is intended to be unique - with the exception of radio buttons, which come in groups. If you name/id more than one element the same, the browser puts the elements in an array - since it can't store them by the same name separately. When it goes looking for the object by name/id, it finds - an array object! Not what you wanted.

    And: use *ids*. That's what document.getElementById() returns - a reference to an id'd element. Names are ignored. Other than form elements, the id is poised to become the standard of identifying HTML elements. blinky got the rest right: pass the id as a string (in quotes) and plug it in (at the function end) into the document.getElementById() method; once you've got that object reference, you've got the element, and you can do with it whatever's supported in scripting.

IMN logo majestic logo threadwatch logo seochat tools logo