OldManRiver Posted November 12, 2008 Share Posted November 12, 2008 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] Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted November 12, 2008 Share Posted November 12, 2008 for starters... you need quotes.... <FORM name="me" ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD='POST'> and <a href="#" onclick="??">Toggle Last</a> the "????" function is unique... its whats in the script Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted November 12, 2008 Author Share Posted November 12, 2008 the "????" function is unique... its whats in the script There is a AJAX call that equals the PHP_SELF action to refresh the screen. That is what I forgot. Thinking will need hidden input field to pass the parms need to the script, but not sure. Thanks! OMR Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted November 13, 2008 Author Share Posted November 13, 2008 All, Oh yeah the command I was looking for was: "<a href='#' onclick='document.forms['me'].submit();'> I added it to my file, but my php is not processing right still. Thanks! OMR Quote Link to comment Share on other sites More sharing options...
trq Posted November 13, 2008 Share Posted November 13, 2008 Post the relevent code! Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted November 13, 2008 Author Share Posted November 13, 2008 Updated vesion of my file attached. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
trq Posted November 13, 2008 Share Posted November 13, 2008 And what exactly is the issue? Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted November 13, 2008 Author Share Posted November 13, 2008 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 Quote Link to comment Share on other sites More sharing options...
trq Posted November 13, 2008 Share Posted November 13, 2008 Sounds more like a Javascript issue to me considering php cannot do anything on the client side. All it does is output strings. Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted November 13, 2008 Author Share Posted November 13, 2008 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 Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted November 14, 2008 Author Share Posted November 14, 2008 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] Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted December 20, 2008 Author Share Posted December 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.