Div Display Problem

Discussion in 'Javascript' started by Erik Lautier, Nov 9, 2006.

  1. Erik Lautier

    Erik Lautier Guest

    Hi, I'm having trouble making a DIV show up; here's the background:
    I'm building a message board system where if the message is more than
    100 characters, the link "more" appears after the first 100 characters.
    When the user clicks it, the full message replaces the truncated one.
    I'm pulling a DIV switch and loading the first (the truncated message)
    as display:block and the second (the full message) as display:none.
    OnClick, the switch is pulled. This *should* be working but I can't
    understand the glitch; when I click on the link, the truncated message
    disappears, but it's not being replaced by anything. Could it be
    because I'm generating the DIVs dynamically? I'm naming them based on
    a message ID from a DataReader, but for testing purposes, I've var'd
    the relevant IDs in the code. Any help would be appreciated; I've
    copied the Javascript and relevant HTML below. Thanks!

    <script language="JavaScript">
    var ids=new Array('ids23','ids24');

    function switchid(id){
    hideallids();
    showdiv(id);
    }

    function hideallids(){
    //loop through the array and hide each element by id
    for (var i=0;i<ids.length;i++){
    hidediv(ids);
    }
    }

    function hidediv(id) {
    //safe function to hide an element with a specified id
    if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'none';
    }
    else {
    if (document.layers) { // Netscape 4
    document.id.display = 'none';
    }
    else { // IE 4
    document.all.id.style.display = 'none';
    }
    }
    }

    function showdiv(id) {
    //safe function to show an element with a specified id

    if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'block';
    }
    else {
    if (document.layers) { // Netscape 4
    document.id.display = 'block';
    }
    else { // IE 4
    document.all.id.style.display = 'block';
    }
    }
    }
    </script>

    <tr><td><p class='level1'><img src='images/point.gif' align='left'
    border='0'><div id='ids23' style="display:block;">What if I write a
    very long reply to this message? Will it return where it should or go
    back to the&nbsp;&nbsp;<a
    href="javascript:switchid('ids24');">...more</a></div><div id='ids24'
    style="display:none;">What if I write a very long reply to this
    message? Will it return where it should or go back to the beginning of
    the line? Stay tuned for the exciting conclusion!</div></td>
    Erik Lautier, Nov 9, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HJ
    Replies:
    5
    Views:
    847
    Jonathan N. Little
    Sep 1, 2006
  2. Leupi
    Replies:
    6
    Views:
    7,821
    Leupi
    Feb 9, 2008
  3. K Viltersten

    <div ... /> and <div ...></div>

    K Viltersten, Mar 30, 2009, in forum: ASP .Net
    Replies:
    4
    Views:
    745
  4. Dwayne Madsen

    Q: Div A inside Div B is larger than Div B

    Dwayne Madsen, Jun 1, 2005, in forum: Javascript
    Replies:
    1
    Views:
    186
    David Dorward
    Jun 1, 2005
  5. mscir
    Replies:
    3
    Views:
    307
    Martin Honnen
    Jun 26, 2005
Loading...

Share This Page