bit of javascript help

Associate
Joined
18 Sep 2003
Posts
904
Hi,

I suck at javscript, so was wondering if someone could assist with the following:

PHP:
function show_all_rows() {

var mytable= document.getElementById('result_table');
var mychild = mytable.firstChild;

while(mychild!=null)
{  mychild.style.display = 'table-row';
    var mychild = mychild.nextSibling;
    alert ("a");
}
}

I don't know if I am remotely going about the right way of doing this, but basically I have a table with certain rows that are hidden with a display: none, and I want this function to un-hide them. The rows that are hidden are no sequential so I can't just put a span around them.

Thanks
 
Thanks for the advice. I have installed the jQuery library and pasted in the code you posted, as follows:

<input type="checkbox" onClick="$('#result_table tr:display').toggle();" />

However, its not working, and Firefox is actually complaining about the jQuery script (line 26, fn is not defined). Any ideas?
 
the way jquery is implemented is different to "normal" javascript.

after including your jquery file, do this:

PHP:
<script type="text/javascript">
  $('input[type="checkbox"]').click(function(){
    $('#result_table tr').toggle();
  });
</script>
 
You've included jquery.js in your <head>, right?

Btw Sic I'm not sure if $('#result_table tr').toggle(); is what he wants, given that it'll hide the visible ones as well as making the hidden ones visible.
 
Code:
<head>
 <title>Page Title</title>

 <script type="text/javascript" src="/path/to/jquery.js"></script>

 <script type="text/javascript">
  $(document).ready(function() {
    $('input[type="checkbox"]').click(function(){
      $('#result_table tr:hidden').toggle();
    });
  });
 </script>

</head>

<body>
...
;)
 
Btw Sic I'm not sure if $('#result_table tr').toggle(); is what he wants, given that it'll hide the visible ones as well as making the hidden ones visible.

I just copied what you'd posted, and edited it for simplicity :o
 
Back
Top Bottom