Reply
collapsible tables ??
Old 07-19-2004, 03:42 PM collapsible tables ??
Unknown.

Posts: 1,693
Anyone be able to help me with the coding for Collapsible tables... Like the ones on the right on this forum??

Thanks

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 07-19-2004, 04:08 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
PHP and Unicode with UTF-8
Posts: 3,108
Location: Toronto, Ontario
In a nutshell, what people do is get Javascript to toggle the display CSS property of a item. display:none will hide the item, and a display of nothing (or the default) will make it display as normal.

Here's a simple rundown version:

Code:
<html>
<head>
    <title> New Document </title>
    <script language="javascript">
    function getItem(id)
    {
        var itm = false;
        if(document.getElementById)
            itm = document.getElementById(id);
        else if(document.all)
            itm = document.all[id];
        else if(document.layers)
            itm = document.layers[id];

        return itm;
    }

    function toggleItem(id)
    {
        itm = getItem(id);

        if(!itm)
            return false;

        if(itm.style.display == 'none')
            itm.style.display = '';
        else
            itm.style.display = 'none';

        return false;
    }
    </script>
</head>
<body>

<table width="400">
    <tbody>
        <tr><td style="background-color: #CCC"><a href="#" onclick="toggleItem('myTbody')">Toggle</a></td></tr>
    </tbody>

    <tbody id="myTbody">
        <tr><td>Test row1</td></tr>
        <tr><td>Test row2</td></tr>
        <tr><td>Test row3</td></tr>
        <tr><td>Test row4</td></tr>
        <tr><td>Test row5</td></tr>
    </tbody>
</table>

</body>
</html>
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Old 07-19-2004, 04:31 PM
Unknown.

Posts: 1,693
Thanks

Been wanting to do this for ages..thought it would be complicated

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 07-21-2004, 05:43 AM
scottfree's Avatar
Extreme Talker

Posts: 234
Location: Hamburg
Great little script Chroder. I donīt know much about javascript but this script is so short and has an amazing effect. This is just what I need for my site.
__________________
I think, therefore I am..... I think.
scottfree is offline
Reply With Quote
View Public Profile Visit scottfree's homepage!
 
Old 07-21-2004, 08:14 AM
Republikin's Avatar
Super Moderator

Posts: 3,191
Hey Chris, how compatable is that little golden nugget?
Republikin is offline
Reply With Quote
View Public Profile
 
Old 07-21-2004, 09:23 AM hi
Mooofasa's Avatar
Defies a Status

Posts: 1,612
Name: Michael (mik) Land
Location: England
You can also find dhtml collapsable scripts at www.dynamicdrive.com


Mik
__________________
Tumblings.co.uk - Tumblog with thoughts, quotes, links, videos, images and my creations.
Opera Browser - The best free web browser.
Opera Dev Tools - Firefox is now Firefail.
Mooofasa is offline
Reply With Quote
View Public Profile Visit Mooofasa's homepage!
 
Old 07-21-2004, 11:50 AM
Unknown.

Posts: 1,693
I have also noticed on this site..That when you minimise the tables they stay like that on every page of the site..

Hows this work??

Using cookies or something??

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 07-21-2004, 11:58 AM
WaHoOoO!'s Avatar
Mentally Unstable Tugboat Captain

Posts: 797
Name: Chad
Location: /usr/bin/perl
Well, with the forum, I would think it has to do with sessions (being PHP).
__________________
He's baaaaaaaack....
WaHoOoO! is offline
Reply With Quote
View Public Profile Visit WaHoOoO!'s homepage!
 
Old 07-21-2004, 12:04 PM hi
Mooofasa's Avatar
Defies a Status

Posts: 1,612
Name: Michael (mik) Land
Location: England
i have tried to view the source code of wemaster-talk, but it does not appear! Why is this? If you have the code then please submit it.
__________________
Tumblings.co.uk - Tumblog with thoughts, quotes, links, videos, images and my creations.
Opera Browser - The best free web browser.
Opera Dev Tools - Firefox is now Firefail.
Mooofasa is offline
Reply With Quote
View Public Profile Visit Mooofasa's homepage!
 
Old 07-21-2004, 12:05 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
PHP and Unicode with UTF-8
Posts: 3,108
Location: Toronto, Ontario
Quote:
Hey Chris, how compatable is that little golden nugget?
The getItem function uses DOM's from all supporting browsers, so it should be fine. If any browser isn't supporting it, the functions return false and nothing is done (not even errors). Should work in: Mozilla, Explorer 4+, Opera 5+, Konqueror, Safari, iCab, Ice, OmniWeb. The problem is with old Netscape 4 where it uses document.layers which means you can only use <div>'s and they have to have a position with it as well.

Quote:
Using cookies or something??
Yes, whenever you click to collapse it it stores a cookie with 'id' of the object. I made something similar to this once, let me know if you want to have that functionality as well
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Old 07-21-2004, 12:14 PM
Unknown.

Posts: 1,693
Would you be able to help me with the coding for that??

I know a little bit about cookies..But I would probally just mess it up

Thanks

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 07-21-2004, 12:32 PM hi
Mooofasa's Avatar
Defies a Status

Posts: 1,612
Name: Michael (mik) Land
Location: England
I have sent Dark-Skys99 a cookie set. It should help. Although what i have sent is PHP.


Mik
__________________
Tumblings.co.uk - Tumblog with thoughts, quotes, links, videos, images and my creations.
Opera Browser - The best free web browser.
Opera Dev Tools - Firefox is now Firefail.
Mooofasa is offline
Reply With Quote
View Public Profile Visit Mooofasa's homepage!
 
Old 07-21-2004, 12:34 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
PHP and Unicode with UTF-8
Posts: 3,108
Location: Toronto, Ontario
Ok, here you go I love Javascript...

Code:
<html>
<head>
    <title> New Document </title>
    <script language="javascript">
    function init()
    {
        var cookie = getCookie('collapse_obj');
        if(cookie)
        {
            var values = cookie.split(',');

            for(var i = 0; i < values.length; i++)
            {
                var itm = getItem(values[i]);

                if(itm)
                    itm.style.display = 'none';
            }
        }
    }

    function makeCookie(name, value)
    {
        var cookie = name + '=' + escape(value) + ';';
        document.cookie = cookie;
    }

    function getCookie(name)
    {
        if(document.cookie == '')
            return false;

        var firstPos;
        var lastPos;
        var cookie = document.cookie;

        firstPos = cookie.indexOf(name);

        if(firstPos != -1)
        {
            firstPos += name.length + 1;
            lastPos = cookie.indexOf(';', firstPos);

            if(lastPos == -1)
                lastPos = cookie.length;

            return unescape(cookie.substring(firstPos, lastPos));
        }

        else
            return false;
    }

    function getItem(id)
    {
        var itm = false;
        if(document.getElementById)
            itm = document.getElementById(id);
        else if(document.all)
            itm = document.all[id];
        else if(document.layers)
            itm = document.layers[id];

        return itm;
    }

    function toggleItem(id)
    {
        itm = getItem(id);

        if(!itm)
            return false;

        if(itm.style.display == 'none')
            itm.style.display = '';
        else
            itm.style.display = 'none';

        ////////////////////

        cookie = getCookie('collapse_obj');
        values = new Array();
        newval = new Array();
        add    = 1;

        if(cookie)
        {
            values = cookie.split(',');

            for(var i = 0; i < values.length; i++)
            {
                if(values[i] == id)
                    add = 0;
                else
                    newval[newval.length] = values[i];
            }
        }

        if(add)
            newval[newval.length] = id;

        makeCookie('collapse_obj', newval.join(','));

        return false;
    }
    </script>
</head>
<body onload="init()">

<table width="400">
    <tbody>
        <tr><td style="background-color: #CCC"><a href="#" onclick="toggleItem('myTbody1')">Toggle 1</a></td></tr>
    </tbody>

    <tbody id="myTbody1">
        <tr><td>Test row1</td></tr>
        <tr><td>Test row2</td></tr>
        <tr><td>Test row3</td></tr>
        <tr><td>Test row4</td></tr>
        <tr><td>Test row5</td></tr>
    </tbody>
</table>

<table width="400">
    <tbody>
        <tr><td style="background-color: #CCC"><a href="#" onclick="toggleItem('myTbody2')">Toggle 2</a></td></tr>
    </tbody>

    <tbody id="myTbody2">
        <tr><td>Test row1</td></tr>
        <tr><td>Test row2</td></tr>
        <tr><td>Test row3</td></tr>
        <tr><td>Test row4</td></tr>
        <tr><td>Test row5</td></tr>
    </tbody>
</table>

<table width="400">
    <tbody>
        <tr><td style="background-color: #CCC"><a href="#" onclick="toggleItem('myTbody3')">Toggle 3</a></td></tr>
    </tbody>

    <tbody id="myTbody3">
        <tr><td>Test row1</td></tr>
        <tr><td>Test row2</td></tr>
        <tr><td>Test row3</td></tr>
        <tr><td>Test row4</td></tr>
        <tr><td>Test row5</td></tr>
    </tbody>
</table>

</body>
</html>
New stuff in bold
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Old 07-21-2004, 12:50 PM hi
Mooofasa's Avatar
Defies a Status

Posts: 1,612
Name: Michael (mik) Land
Location: England
I love javascript too, but php is better at cookies than java.

In my oppinion anyway
__________________
Tumblings.co.uk - Tumblog with thoughts, quotes, links, videos, images and my creations.
Opera Browser - The best free web browser.
Opera Dev Tools - Firefox is now Firefail.
Mooofasa is offline
Reply With Quote
View Public Profile Visit Mooofasa's homepage!
 
Old 07-21-2004, 01:00 PM
Republikin's Avatar
Super Moderator

Posts: 3,191
cookies are cookies. You can only do so much with them and they both do exactly what you can? What makes php better?
Republikin is offline
Reply With Quote
View Public Profile
 
Old 07-21-2004, 01:17 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
PHP and Unicode with UTF-8
Posts: 3,108
Location: Toronto, Ontario
Javascript and PHP grab onto the same cookies, nothing differing. At least with Javascript you can do things instantly whereas with PHP you'd need a whole new pageload.
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Old 07-21-2004, 01:31 PM hi
Mooofasa's Avatar
Defies a Status

Posts: 1,612
Name: Michael (mik) Land
Location: England
Very well, but i PM Dark-Skys99 with the PHP code anyway.


Mik
__________________
Tumblings.co.uk - Tumblog with thoughts, quotes, links, videos, images and my creations.
Opera Browser - The best free web browser.
Opera Dev Tools - Firefox is now Firefail.
Mooofasa is offline
Reply With Quote
View Public Profile Visit Mooofasa's homepage!
 
Old 07-21-2004, 01:36 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
PHP and Unicode with UTF-8
Posts: 3,108
Location: Toronto, Ontario
It can't be done with PHP. With PHP you'd have to load the page over and over again on each collapse which is obviously inefficient.

PHP is a server side language, this is a client side problem and solution.

(btw, I think there is an error in my code. I'll check it out later.)
__________________
Devlog - Latest Articles: MVC with the Zend Framework, PHP and UTF8
::<