Jump to content

[SOLVED] Collapsing Rows


OldManRiver

Recommended Posts

All,

 

Have this script with collapsing rows.  Works fine for just HTML with JavaScript, but when trying to process in PHP, it bombs.

 

I'm sure it is because the PHP has to refresh itself, which is done with the combination of:

<FORM name=me ACTION=<?php echo $_SERVER['PHP_SELF']; ?> METHOD='POST'>

and

<a href="#" onclick="??">Toggle Last</a>

but I've forgotten:

[*]What command goes in for the ??,

[*]How to pass the id and name parms to the JavaScript.

I've attached my script.

 

Thanks!

 

OMR

 

[attachment deleted by admin]

Link to comment
Share on other sites

And what exactly is the issue?

Did you try the file?

 

If you did you would see that table1 does not collapse as it is declared in PHP.  All others do work, but my existing code page I'm working on, is already in production and uses the PHP method for table1, so must make that code work.

 

OMR

 

Link to comment
Share on other sites

Sounds more like a Javascript issue to me considering php cannot do anything on the client side. All it does is output strings.

Well you are partially right.  I found some code and added:

var serverPage = "calendar.php";

xmlhttp.open("GET", serverPage);

to my script resulting in:

    function toggleItem(id) {

        itm = getItem(id);

        if(!itm)

            return false;

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

            itm.style.display = '';

var serverPage = "calendar.php";

xmlhttp.open("GET", serverPage);

        else

            itm.style.display = 'none';

        return false;

    }

But this just opens a new window with the existing page.  I need to reopen existing page and looks like I need to add $_SESSION vars to trap the state of the tables, etc by element ID.  So PHP will know what state to put the rows in based on what AJAX is passing it or vice-versa.

 

Not sure how to do this yet, but working on it.

 

Thanks!

 

OMR

 

Link to comment
Share on other sites

All,

 

Thanks much for the pointers. Got some basic feedback from users at:

 

http://forums.codewalkers.com/php-coding-7/collapsing-rows-908475.html

http://forums.devshed.com/php-development-5/collapsing-rows-570247.html#post2156989

 

I knew I was close, mainly just syntax keeping me out. Have made the changes to my sample file and my production file and they work fine. I also moved all three of the tables in the first group into php.

 

Now I want these table rows to init in the collapsed state, just like the columns in the second table group. I'm sure the function they used:

function setupTables() {

var tables = document.getElementsByTagName('table');

for (var tableLoop=0; tableLoop<tables.length; tableLoop++) {

if (tables[tableLoop].className == 'collapseColumns') {

var headerRow = tables[tableLoop].tHead.rows[0].cells;

for (var cellLoop=0; cellLoop<headerRow.length; cellLoop++) {

headerRow[cellLoop].onclick = toggleColumn;

headerRow[cellLoop].style.cursor = 'pointer';

}

}

}

}

is what I need to invoke, but not sure what parms are needed.

 

If you know please chime in.

 

Thanks a lot again!

 

OMR

 

[attachment deleted by admin]

Link to comment
Share on other sites

  • 1 month later...

All,

 

I got this fixed. Found that syntax in my code was major problem. Code is (javascript):

    <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>

 

(PHP)

<a href='#' onclick=\"toggleItem('myTbody[$i]')\">

 

Notice the placement of the single and double quotes and the "\" escape character needed for correct processing.

 

Thanks All!

 

OMR

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.