SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2004
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question some function that could do it...

    hi,
    would be great someone could help me on this

    <html><head><title>Untitled Document</title>

    <script type="text/javascript">
    function lstFlip(lstBlock,lstItem) {
    if (document.getElementById(lstBlock).style.display == 'block') {
    document.getElementById(lstBlock).style.display = 'none';
    if (lstItem != undefined) {document.getElementById(lstItem).style.background = "none";}
    } else {
    document.getElementById(lstBlock).style.display = 'block';
    if (lstItem != undefined) {document.getElementById(lstItem).style.backgroundColor ="#C7C7C7";}
    }
    }

    function loadLinks(listId) {
    if (listId.length > 1){lstFlip('lstBlock'+listId.charAt(0),'lst'+ listId.charAt(0)); }
    lstFlip('lstBlock'+listId);
    }
    </script>


    <style type="text/css">
    body,a {font-family:"verdana"; font-size:12px;}
    .lstMenu {margin:0;list-style-type:none; border:1px solid #728FAD; padding:10px 0 10px 0px; width:180px; }
    .lstMenu li {cursorointer; height:25px; padding:0; margin:0;font-size:10px;}
    .lstMenu li span {width:100%; height:25px; padding:5px 0 0 15px; margin:0;}
    .lstMenu li a {font-size:12px; padding-left:20px; color:#003366; margin-left:5px; text-decoration:none; }
    .lstMenu li a:hover {font-size:12px; text-decoration:underline;}
    .lstMenu ul {display:none; list-style-type:none; margin:1px 0 1px 10px; padding:0;}
    .lstMenu ul li {background:none;margin:0; padding:0; border:0; height: 20px;}
    .lstMenu ul li a {font-size:12px; font-weight:100;}
    .lstMenu ul li a#active {color:#FF6600;}

    </style>

    </head><body>

    <ul class="lstMenu">
    <li><span id="lst1" onclick="lstFlip('lstBlock1','lst1');">Menu Item</span></li>
    <ul id="lstBlock1">
    <li><span onclick="lstFlip('lstBlock1_1');">Menu Item</span></li>
    <ul id="lstBlock1_1">
    <li><a href="#">menu item2</a></li>
    <li><a href="#">menu item2</a></li>
    </ul>
    <li><a href="#" id="active">menu item2</a></li>
    <li><a href="#">menu item2</a></li>
    <li><a href="#">menu item2</a></li>
    </ul>

    <li><span id="lst2" onclick="lstFlip('lstBlock2','lst2');">Menu Item</span></li>
    <ul id="lstBlock2">
    <li><a href="#">menu item2</a></li>
    <li><a href="#">menu item2</a></li>
    <li><a href="#">menu item2</a></li>
    </ul>
    </ul>
    </body></html>
    -----------------------------------

    if i set on the page load:loadLinks("1");
    it gives me what i want, i load the page and the unordered List "tree" is open where i have the link with the Id="active";

    what i want...
    is it possible to have a function that OnLoad searches the "lstMenu"
    for a link with the id="active",and returns the id of the "belonging" list of that link, giving me the desired effect without passing any arguments?

    thanks

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Frost,

    You can achieve what you're asking by collecting the "<a>" tags, stepping through them until you find the ID, then stepping up through the parentNode(s) to get the listId. But...rather than all of that (I'm presuming you want to maintain the user's selection), why don't you write a cookie, read it, and call lstFlip with the cookie's value?

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2004
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Vincent Puglia
    Hi Frost,

    You can achieve what you're asking by collecting the "<a>" tags, stepping through them until you find the ID, then stepping up through the parentNode(s) to get the listId. But...rather than all of that (I'm presuming you want to maintain the user's selection), why don't you write a cookie, read it, and call lstFlip with the cookie's value?

    Vinny
    hi Vinny,

    ... personally, i avoid the use of cookies, but it's something to consider...
    i managed to do what i wanted, using a function that does "sort of " what you described , it's not as "flexible" as i wanted, but it does the trick...

    still, thanks for the advice


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
  •