SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JAVASCRIPT and PHP Problem....! Need Urgent help...

    Hi

    I tried to creating a folder tree collopse and expand to use in faqs page.

    here is my php file: code

    <table width="187" border="0" cellpadding="0" cellspacing="0">
    <tbody>
    <tr>
    <td width="187"><a href="javascript:exp_all();"><img src="images/plus.gif"
    alt="toggle" width="18" height="18" border="0" /></a>&nbsp;<span class="bluenormal">Expand all</span> <a
    href="javascript:coll_all();"><img src="images/minus.gif" alt="toggle" width="18" height="18" border="0" /></a>&nbsp;&nbsp;<span class="bluenormal">Collapse all</span>
    <ul
    style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px; LIST-STYLE-TYPE: none">
    <?php
    $faq_select=mysql_query("select distinct (topic) from faq order by topic asc");
    $j=0;
    while ($faq_fetch=mysql_fetch_array($faq_select))
    {
    $j++;
    if ($j=='1')
    $k=0;
    if ($j=='2')
    $k=10;
    if ($j=='3')
    $k=15;
    if ($j=='4')
    $k=22;
    if ($j=='5')
    $k=37;
    if ($j=='6')
    $k=48;
    ?>
    <li><a href="javascript:exp_coll(<?php echo $k; ?>);"><img
    src="images/minus.gif" alt="toggle" name="im_0" width="18" height="18" border="0" id="im_0" /></a> <img src="images/folder-open.gif" alt="icon" name="im2_0" width="18"
    height="18"
    id="im2_0" /> <a href="javascript:exp_coll(<?php echo $k; ?>);"><font class="bluenormal">

    <?php echo $faq_fetch['topic']; ?></font></a>
    <?php
    $question_select=mysql_query("select * from faq where topic='$faq_fetch[topic]' order by question asc");
    while ($question_fetch=mysql_fetch_array($question_select))
    {
    ?>
    <ul style="DISPLAY: block" id="sp_0" class="zzul">
    <li></li>
    <SPAN class=zzspace>&nbsp;&nbsp; <img alt="icon"
    src="images/html.gif" width="18" height="18" /> <a href="faqs.php?faqid=<?php echo $question_fetch['id']; ?>">
    <?php echo $question_fetch['question']; ?></a>
    </ul>
    <?php
    }
    ?>
    </li>
    <?php
    }
    ?>
    </ul></td>
    </tr>
    </tbody>
    </table>


    and here is my javascript code:

    function exp_coll(ind)
    {
    s = document.getElementById("sp_" + ind);
    i = document.getElementById("im_" + ind);
    i2 = document.getElementById("im2_" + ind);
    if (s.style.display == 'none')
    {
    s.style.display = 'block';
    i.src = "images/minus.gif";
    i2.src = "images/folder-open.gif";
    }
    else if (s.style.display == 'block')
    {
    s.style.display = 'none';
    i.src = "images/plus.gif";
    i2.src = "images/folder.gif";
    }
    }

    function exp(ind)
    {
    s = document.getElementById("sp_" + ind);
    i = document.getElementById("im_" + ind);
    i2 = document.getElementById("im2_" + ind);
    if (!(s && i && i2)) return false;
    s.style.display = 'block';
    i.src = "images/minus.gif";
    i2.src = "images/folder-open.gif";
    }

    function coll(ind)
    {
    s = document.getElementById("sp_" + ind);
    i = document.getElementById("im_" + ind);
    i2 = document.getElementById("im2_" + ind);
    if (!(s && i && i2)) return false;
    s.style.display = 'none';
    i.src = "images/plus.gif";
    i2.src = "images/folder.gif";
    }

    function coll_all()
    {

    coll(0);
    coll(10);
    coll(15);
    coll(22);
    coll(37);
    coll(48);
    coll(119);
    coll(126);
    coll(139);
    coll(141);
    coll(150);
    coll(151);
    coll(158);
    coll(160);
    }

    function exp_all()
    {

    exp(0);
    exp(10);
    exp(15);
    exp(22);
    exp(37);
    exp(48);
    exp(119);
    exp(126);
    exp(139);
    exp(141);
    exp(150);
    exp(151);
    exp(158);
    exp(160);
    }


    It is working but the problem is only the first row I am able to colospe but not other.

    I request you help in solving the above problem.

    Your comments and suggestions will be highly appreciated.\

    Regards

  2. #2
    SitePoint Zealot loathsome's Avatar
    Join Date
    Jul 2008
    Location
    Norway
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not take a look at already existing solutions? I can recommend Treeview JavaScript tree menu (demo)

    There's also lots of other alternatives out there.

    No point in reinventing the wheel, you know
    Time you enjoy wasting is not wasted time.

    Loathsome Systems


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
  •