Javascript Show/Hide in PHP Loop problem

Discussion in 'JavaScript' started by koolsamule, Sep 3, 2009.

  1. #1
    Hi Guys,

    I have a PHP loop region, which repeats all completed projects for each customer, then displays all jobsheets linked to those projects.
    I have a javascript show/hide function, which will only show the jobsheets when the project link is clicked.
    Without this javascript, the PHP loop works perfectly, but all the information is displayed. How can I use the show/hide function and still show all the jobsheets for completed projects?

    function toggle2(id, link) {
      var e = document.getElementById(id);
     
      if (e.style.display == '') {
        e.style.display = 'none';
        link.innerHTML = '<img src="../Images/plus.gif" border="0" >';
      } else {
        e.style.display = '';
        link.innerHTML = '<img src="../Images/minus.gif" border="0" >';
      }
    }
    Code (markup):
    <table>
    <tr>
    <th>Project / Job</th>
    <th>Language</th>
    <th>Words (Net)</th>
    <th>Shipped</th>
    </tr>
    
    <?php
    $previousProject = '';
    if ($totalRows_rsComplete_Cust > 0) {
    // Show if recordset not empty
    while ($row_rsComplete_Cust = mysql_fetch_assoc($rsComplete_Cust)) {
    if ($previousProject != $row_rsComplete_Cust['projid']) {
    // for every user, show the user name
    ?>
    
    <tr>
    <td colspan="4"><a href="#" onclick="toggle2('<?php echo $row_rsComplete_Cust['projid']; ?>', this)"><img src="../Images/plus.gif" border="0" /></a><?php echo $row_rsComplete_Cust['projid']; ?></td>
    </tr>
    
    <?php $previousProject = $row_rsComplete_Cust['projid']; } ?>
    
    <tr id="<?php echo $row_rsComplete_Cust['projid']; ?>" style="display:none">
    <td><a href="jobsheet_details.php?id=<?php echo $row_rsComplete_Cust['jobid']; ?>&amp;proj=<?php echo $row_rsComplete_Cust['projid']; ?>"><?php echo $row_rsComplete_Cust['jobname']; ?></a></td>
    <td>LANGUAGE</td>
    <td>WORD NET</td>
    <td>YES / NO</td>
    </tr>  
    
    <?php }} // Show if recordset not empty ?>
    
    </table> 
    PHP:
     
    koolsamule, Sep 3, 2009 IP
  2. caprichoso

    caprichoso Well-Known Member

    Messages:
    433
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    110
    #2
    I'm not sure what's working and what isn't.

    For a start you may like to change:
    
    onclick="toggle2('<?php echo $row_rsComplete_Cust['projid']; ?>', this)">
    
    onclick="javascript: return toggle2('<?php=$row_rsComplete_Cust['projid']; ?>', this)">
    
    PHP:
    
    function toggle2(id, link) {
      var e = document.getElementById(id);
     
      if (e.style.display == '') {
        e.style.display = 'none';
        link.innerHTML = '<img src="../Images/plus.gif" border="0" >';
      } else {
        e.style.display = '';
        link.innerHTML = '<img src="../Images/minus.gif" border="0" >';
      }
    
      return false;
    }
    
    Code (markup):
    Just added a return false to the end.
     
    caprichoso, Sep 4, 2009 IP