View Full Version : Ok to do this? put an onclick in a TR

02-15-2008, 11:05 PM
Just wanted to check to make sure this practice is ok prior to heading down the road with this code. It validates but is it ok to put an onclick in a TR tag.

<table class="listview" width="700">
<tr><td colspan="4" class="msgblock"><?php echo $var_message; ?></td></tr>
<tr class="listheader">
<th>Last Name</th>
<th>First Name</th>
<?php if ($loop > 0) { for ($i=0; $i<$loop; $i++) { ?>
<tr class="<?php echo ($i % 2) ? 'listRow0' : 'listRow1'; ?>" onclick="window.location='<?php echo $_SERVER['PHP_SELF'] ?>?action=Display&amp;id=<?php echo $data_all[$i]['ID'] ?>'">
<td><?php echo $data_all[$i]['last_name'] ?></td>
<td><?php echo $data_all[$i]['first_name'] ?></td>
<td><?php echo $data_all[$i]['email_add'] ?></td>
<td><?php echo $data_all[$i]['phone'] ?></td>
<?php } } ?>

02-16-2008, 03:37 AM
I'm almost positive it is, I've seen it done with javascript, don't why you cant with PHP

02-16-2008, 03:55 AM
This has nothing to do with PHP, and even if it would be written through PHP the output is still JS. And yes, you can do that. I don’t see any reason why you shouldn’t. As long as an element belongs to the DOM you can manipulate it with JS.

02-16-2008, 04:46 AM
How does this have nothing to do with php?

02-17-2008, 12:31 AM
because, I think, the issue is about (x)html coding rather than how it is sent to the browser. The output (source view) only shows the finished html which is where any issue about the <tr> would be evident.