Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Ok to do this? put an onclick in a TR

    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.

    Code:
    <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>
    		<th>E-Mail</th>
    		<th>Phone</th>
    	</tr>
    	<?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>
    		</tr>
    	<?php } } ?>
    </table>

  • #2
    Regular Coder kosstr12's Avatar
    Join Date
    Apr 2007
    Location
    Woodstock, Georgia
    Posts
    428
    Thanks
    7
    Thanked 5 Times in 5 Posts
    I'm almost positive it is, I've seen it done with javascript, don't why you cant with PHP

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,676
    Thanks
    6
    Thanked 1,008 Times in 981 Posts
    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.

  • Users who have thanked VIPStephan for this post:

    JimM (02-18-2008)

  • #4
    Regular Coder kosstr12's Avatar
    Join Date
    Apr 2007
    Location
    Woodstock, Georgia
    Posts
    428
    Thanks
    7
    Thanked 5 Times in 5 Posts
    How does this have nothing to do with php?

  • #5
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    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.

    bazz


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •