943,170 Members | Top Members by Rank

Ad:
Sep 2nd, 2010
0

Show / Hide table rows via checkboxes

Expand Post »
Hello everyone,

I hoping you can help me. I've got a table that I want to be able to show/hide rows based on what check box is checked. By default, I don't want anything displayed, then if you check a or some of the check boxes you'll see the data.

Here is what I have, which has some effect in FF but does not work at all in IE.

This is my script (which is part mine, part web-found)
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <style type="text/css">
  2.  
  3. .this {
  4. display: none;
  5. }
  6. .this2 {
  7. display: none;
  8. }
  9. </style>
  10. <script>
  11. function showRow(obj,klassName){
  12. var elems = document.getElementsByName(klassName);
  13. var newDisplay = "none";
  14. if(obj.checked == true){
  15. newDisplay = "block";
  16. }
  17. for(var idx=0; idx < elems.length ; idx++){
  18. elems[idx].style.display = newDisplay;
  19. }
  20. }
  21. </script>

And this is the HTML that I have

The boxes:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. Filter Options </br>
  2. <input type='checkbox' id="1" value="yes" onclick="showRow(this,'x')"/>This 1
  3. <input type="checkbox" id="2" onclick="showRow(this,'y')"/>This 2

The rows via PHP (this part does work, it adds the TR classes to the proper rows):
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. If ($row['Facility'] == "SHEC") {
  2. $trid = "<tr class='this1' name='x'>";
  3. }else{
  4. $trid = "<tr class='this2' name='y'>";
  5. }

If anyone could provide some insight, I would greatly appreciate it.

Thank you!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
agr8lemon is offline Offline
30 posts
since Aug 2009
Sep 3rd, 2010
0
Re: Show / Hide table rows via checkboxes
Try
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. newDisplay = "";
instead of
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. newDisplay = "block";

What it will do is that it will try to remove any style applied and try to set it to the elements inherent values and as a result should work in both FF and IE.

Hope this helps
Sponsor
Reputation Points: 26
Solved Threads: 41
Junior Poster
parry_kulk is offline Offline
166 posts
since Jan 2007
Sep 3rd, 2010
0
Re: Show / Hide table rows via checkboxes
Thanks for the help!

That works great in FF, but IE still does nothing when you check or uncheck the boxes. Any other suggestions?
Reputation Points: 10
Solved Threads: 0
Light Poster
agr8lemon is offline Offline
30 posts
since Aug 2009
Sep 3rd, 2010
0
Re: Show / Hide table rows via checkboxes
Along with the display property also try the visibility property,
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. ........
  2. var newDisplay = "none";
  3. var newVisibility = "hidden";
  4. if(obj.checked == true){
  5. newDisplay = "";
  6. newVisibility = "visible";
  7. }
  8. for(var idx=0; idx < elems.length ; idx++){
  9. elems[idx].style.display = newDisplay;
  10. elems[idx].style.visibility = newVisibility;
  11. }
  12. .........

Also add the visibility property in the css
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. ......
  2. .this {
  3. display: none;
  4. visibility: hidden;
  5. }
  6. .this2 {
  7. display: none;
  8. visibility: hidden;
  9. }
  10. ............
Last edited by parry_kulk; Sep 3rd, 2010 at 9:18 am.
Sponsor
Reputation Points: 26
Solved Threads: 41
Junior Poster
parry_kulk is offline Offline
166 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Printscreen Help
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Replace Content from AJAX Result (SACK)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC