468,490 Members | 2,558 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,490 developers. It's quick & easy.

how to hide unchecked row in table

9
how can we hide unchecked row in table

i hv a table with about 30 rows which have a checkbox and a bit of text each. What i am attempting to get a approach to do is to have 2 buttons at the bottom of the page - HIDE & SHOW. When the HIDE button is clicked i wana to hide all of the table rows which have UNCHECKED textboxes. When the SHOW button is clicked i wish to restore the visibility of all of the rows. i wana to do this in JavaScript (which is what i am getting problem with) - i have been capable to get bits of it to work at number of times but i am executing out of time and I actually i wana help. Any idea somebody has would be more than appreciated!

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
  5. <title>View records in MySQL</title> 
  6.  
  7. </head> 
  8.  
  9. <body> 
  10.  
  11. <?php 
  12. //connect to the database 
  13. $connect = mysql_connect("localhost","root",""); 
  14. mysql_select_db("login",$connect); //select the table
  15. $query = mysql_query( "SELECT * FROM employee ")or die(mysql_error());
  16. $show=$_POST['show'];
  17.  
  18.  
  19.  
  20.  
  21. $timezone = "Asia/Calcutta";
  22. if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
  23.  
  24.  
  25.     echo"<center><h2>";
  26.           echo "Cover id generate at :".date('d-m-Y g:i a');
  27.  
  28.           echo "</h2></center>";
  29.           // generate cover id using random number
  30.     $rand= rand();
  31.     echo"<center><h2>";
  32.           echo "Cover Id :".$rand;
  33.           echo "</h2></center>";
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. echo'
  42. <form action="'.$_SERVER['PHP_SELF'].'" method="post">
  43. <table width="100%" cellpadding="4" border="1">
  44. <tr>
  45. <td> id  </td>
  46. <td> reg_no  </td>
  47. <td> reg_time  </td>
  48. <td>name   </td>
  49. <td> email_id  </td>
  50. <td> valid_from  </td>
  51. <td> valid_to  </td>
  52. <td> pan_no  </td>
  53. <td>  policy </td>
  54. <td> org_name  </td>
  55. <td> reseller_id  </td>
  56. <td> reseller_name </td>
  57. <td>mark</td>
  58. </tr>';
  59.  
  60. while($row = mysql_fetch_assoc($query))
  61. {
  62.     echo'
  63. <tr>
  64. <td>'.$row['id'].'</td>
  65. <td>'.$row['reg_no'].'</td>
  66. <td>' .$row['reg_time'].'</td>
  67. <td>'.$row['name'].'</td>
  68. <td>'.$row['email_id'].'</td>
  69. <td>'.$row['valid_from'].'</td>
  70. <td>' .$row['valid_to'] .'</td>
  71. <td>'.$row['pan_no'].'</td>
  72. <td>' .$row['policy'].'</td>
  73. <td> '.$row['org_name'].'</td>
  74. <td>'.$row['reseller_id'].'</td>
  75. <td>' .$row['reseller_name'].'</td>
  76. <td><input type="checkbox" name="id[]" value="'.$row['id'].'"></td>
  77.  
  78. </tr>';    
  79. }
  80. mysql_free_result($query);
  81. echo '
  82. </table>
  83. <br>
  84. <div align="center">
  85.  
  86. <input type="submit" name="show"  value="show"  >
  87. <input type="reset" name="cancel"  value="Cancel mark">
  88. </div>
  89. </form>';
  90.  
  91. ?> 
  92.  
  93.  
  94. </body> 
  95. </html> 
  96.  
May 2 '13 #1
2 3198
Rabbit
12,513 Expert Mod 8TB
I don't see any javascript. It would help to see your javascript along with any error messages you're getting. It would also help to see the HTML source from the client side. We don't need the PHP stuff getting in the way.
May 2 '13 #2
Sherin
77 64KB
Try This Code

Expand|Select|Wrap|Line Numbers
  1. $("button").click(function(){
  2.     $("table tr").has(".check-box:not(:checked)").hide();
  3. });
  4. table, tr, td {
  5.     border: 1px solid black;
  6. }
  7. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  8. <table>
  9.     <tr>
  10.         <th>Name</th>
  11.         <th>InUse</th>
  12.     </tr>
  13.     <tr>
  14.         <td>foo 1</td>
  15.         <td>
  16.             <input class="check-box" type="checkbox" checked disabled  />
  17.         </td>
  18.     </tr>
  19.     <tr>
  20.         <td>foo 2</td>                  
  21.         <td>
  22.             <input class="check-box" type="checkbox" disabled  />
  23.         </td>
  24.     </tr>
  25.     <tr>
  26.         <td>foo 3</td>                  
  27.         <td>
  28.             <input class="check-box" type="checkbox" checked disabled  />
  29.         </td>
  30.     </tr>
  31.     <tr>
  32.         <td>foo 4</td>                  
  33.         <td>
  34.             <input class="check-box" type="checkbox" disabled  />
  35.         </td>
  36.     </tr>
  37. </table>
  38. <button>Only checked</button>
Jan 11 '21 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Steve Bishop | last post: by
7 posts views Thread by Mad Scientist Jr | last post: by
10 posts views Thread by oLE | last post: by
3 posts views Thread by evanburen | last post: by
6 posts views Thread by Ian Collins | last post: by
6 posts views Thread by michael941 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.