Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Show/Hide in PHP Loop problem

Status
Not open for further replies.

koolsamule

Programmer
Sep 3, 2009
3
0
0
GB
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" >';
}
}

<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>
 
I assume you want to be able to click a cell in column 1 of your table, and have all the other cells in that row display (and I assume any other set of cells that were previously visible as the result of a click, to be hidden).

If this is the case, then you need to use javascript to identify the sibling cells in the same row and then set the visibility:hidden (instead of display:none) on them.

You may find more luck if you post a cut-down HTML example (no PHP - just the code as rendered on the browser using view source). Putting just 3 projects in... with fake data etc.

Cheers,
Jeff

[tt]Visit my blog [!]@[/!] Visit Code Couch [!]@[/!] [/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top