<html> <head> <title>ThaiCreate.Com Checkbox Highlight tr BackGround,bg Colors</title> </head> <body> <script language="JavaScript"> function ClickCheckAll(vol) { var i=1; for(i=1;i<=document.frmMain.hdnCount.value;i++) { if(vol.checked == true) { eval("document.frmMain.chkDel"+i+".checked=true"); eval("document.getElementById('tr"+i+"').bgColor='#CCCCCC'"); } else { eval("document.frmMain.chkDel"+i+".checked=false"); eval("document.getElementById('tr"+i+"').bgColor='#FFFFFF'"); } } } function ClickMakeColor(chk,ctrl) { if(chk.checked) { document.getElementById(ctrl).bgColor='#CCCCCC' } else { document.getElementById(ctrl).bgColor='#FFFFFF' } } </script> <form name="frmMain" action="" method="post" OnSubmit="return onDelete();"> <?php $objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database"); $objDB = mysql_select_db("mydatabase"); $strSQL = "SELECT * FROM customer"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); ?> <table width="600" border="1"> <tr> <th width="91"> <div align="center">CustomerID </div></th> <th width="98"> <div align="center">Name </div></th> <th width="198"> <div align="center">Email </div></th> <th width="97"> <div align="center">CountryCode </div></th> <th width="59"> <div align="center">Budget </div></th> <th width="71"> <div align="center">Used </div></th> <th width="30"> <div align="center"> <input name="CheckAll" type="checkbox" id="CheckAll" value="Y" onClick="ClickCheckAll(this);"> </div></th> </tr> <?php $i = 0; while($objResult = mysql_fetch_array($objQuery)) { $i++; ?> <tr id="tr<?php echo $i;?>"> <td><div align="center"><?php echo $objResult["CustomerID"];?></div></td> <td><?php echo $objResult["Name"];?></td> <td><?php echo $objResult["Email"];?></td> <td><div align="center"><?php echo $objResult["CountryCode"];?></div></td> <td align="right"><?php echo $objResult["Budget"];?></td> <td align="right"><?php echo $objResult["Used"];?></td> <td align="center"><input type="checkbox" name="chkDel[]" id="chkDel<?php echo $i;?>" value="<?php echo $objResult["CustomerID"];?>" OnClick="ClickMakeColor(this,'tr<?php echo $i;?>');"></td> </tr> <?php } ?> </table> <?php mysql_close($objConnect); ?> <input type="hidden" name="hdnCount" value="<?php echo $i;?>"> </form> </body> </html>