views:

96

answers:

1
function expandAll(table,val){   
        if (document.getElementById) {
  var row;
  var rown;
  var tblname;
  if ((tblname = document.getElementById(table + 'Tab')) != null) {

   var totRows = tblname.rows.length;

   if (val == 'show') {   
      for(i=0;i < totRows;i++){
       rowid = table+ i;
         if ((row = document.getElementById(rowid)) != null) {
         row.style.display='block';
      }

     }
   }
 }

In the above function When Clicking on hyperlink of expand all or collapse all with the value show it calls the above function it expands all the rows that have details for each row in the table .We need Jquery code of this javascript function.here "table" refers to the table name and

+1  A: 

Based on your previous question as well it looks like this is what you're after:

function expandAll(table, val) {   
  if(val == 'show') {
    $('#' + table  + 'Tab tr').show();
  }
}

If val is either "show" or "hide", you can make it work both ways, like this:

function expandAll(table, val) {   
  $('#' + table  + 'Tab tr')[val]();
}

Or, if val (we'll rename to show to be clear) can be true or false for show/hide, you can use .toggle() like this:

function expandAll(table, show) {   
  $('#' + table  + 'Tab tr').toggle(show);
}
Nick Craver
I will Be calling on Document.onload with the click event function for hyper link
Someone
$(document).ready(function(){ $('#showdetails').click(function(){ var totrows= $('#dspRefTableTab').attr('rows').length; for(i=0; i < totrows; i++){ //rowid = ("#dspRefTable"+i); //var rowval = ("#rowid"); //if (rowval!= null) { ("#dspRefTableTab < #dspRefTable"+i).css"display","block"); //Getting Error in the above line //} ("#hi_refdet").val='block'; } });
Someone
@Someone - You should post in the question how you intend to use it, e.g. how it's *currently* called. I suggest you pause and read this: [How to ask great questions](http://meta.stackoverflow.com/questions/8072/how-to-ask-great-questions) so you can get some more useful/applicable answers.
Nick Craver
@Someone - You need to use the function....you're asking a question bout one thing when doing something *completely* different. If you need the function you posted, use it, like this: `$(function(){ $('#showdetails').click(function(){ expandAll('dspRefTableTab', 'show'); }); });`
Nick Craver
on loading the Document Iam calling the click function of hyperlink and Ihave some rows in the table where i can show the details of each row in the table by passing hi_refdat with the value of "block" for showing
Someone
@nick I have to get rid of the expandall function in javascript and use it in jquery.
Someone
@Someone - jQuery *is* JavaScript, it's just an abstraction adding handy shortcuts and cross-browser normalization...you can use a normal function just like any place else. You can have it inline, like this: `$(function(){ $('#showdetails').click(function(){ $('#dspRefTableTabTab tr').show(); }); });` if you want as well.
Nick Craver