title: table2CSV.js - Works wonderful, but having issues specifying which table to export
body: <p>I'm having trouble exporting using table2CSV.js when there are multiple tables on the page.  </p>
  
  <p>The first one will work correctly, but any other buttons will export a blank file.  Any ideas?  If you need more info please advise.</p>
  
  <p>I want to add that it's always the first table on the page that works correctly... </p>
  
  <p>Please review single the call (JS):</p>
  
  <pre><code>function getCSVData(tableName){
      var csv_value=$(tableName).table2CSV({delivery:'value'});
      $("#csv_text").val(csv_value);
  }
  </code></pre>
  
  <p>And the HTML form buttons to call the JS (there are a few on the page):</p>
  
  <pre><code>&lt;form action="getCSV.php" method ="post" &gt; 
      &lt;input type="hidden" name="csv_text" id="csv_text"&gt;
      &lt;input type="hidden" name="fileName" id="fileName" value="&lt;?php echo($fileName); ?&gt;"&gt;
      &lt;input type="submit" value="Download Table 0" onclick="getCSVData('table#detail0')"&gt;
  &lt;/form&gt;
  
  
  &lt;form action="getCSV.php" method ="post" &gt; 
      &lt;input type="hidden" name="csv_text" id="csv_text"&gt;
      &lt;input type="hidden" name="fileName" id="fileName" value="&lt;?php echo($fileName); ?&gt;"&gt;
      &lt;input type="submit" value="Download Table 1" onclick="getCSVData('table#detail1')"&gt;
  &lt;/form&gt;
  
  &lt;form action="getCSV.php" method ="post" &gt; 
      &lt;input type="hidden" name="csv_text" id="csv_text"&gt;
      &lt;input type="hidden" name="fileName" id="fileName" value="&lt;?php echo($fileName); ?&gt;"&gt;
      &lt;input type="submit" value="Download Table 2" onclick="getCSVData('table#detail2')"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is a few table open tags for reference as well:</p>
  
  <p>
  
  </p>
  
  <p>For reference, here's the getCSV.php file</p>
  
  <pre><code>&lt;?php
      $file = $_REQUEST['fileName'];
      $filename = $file."_".date("Y-m-d_H-i",time());
      header("Content-type: application/vnd.ms-excel");
      header("Content-disposition: csv" . date("Y-m-d") . ".csv");
      header( "Content-disposition: filename=".$filename.".csv");
  
      $csv_output=stripcslashes($_REQUEST['csv_text']);
      print $csv_output;
      exit;   
  
  ?&gt;
  </code></pre>
  
  <p>For reference, here's the table2CSV.js code:</p>
  
  <pre><code>jQuery.fn.table2CSV = function(options) {
      var options = jQuery.extend({
          separator: ',',
          header: [],
          delivery: 'popup' // popup, value
      },
      options);
  
      var csvData = [];
      var headerArr = [];
      var el = this;
  
      //header
      var numCols = options.header.length;
      var tmpRow = []; // construct header avalible array
  
      if (numCols &gt; 0) {
          for (var i = 0; i &lt; numCols; i++) {
              tmpRow[tmpRow.length] = formatData(options.header[i]);
          }
      } else {
          $(el).filter(':visible').find('th').each(function() {
              if ($(this).css('display') != 'none') tmpRow[tmpRow.length] = formatData($(this).html());
          });
      }
  
      row2CSV(tmpRow);
  
      // actual data
      $(el).find('tr').each(function() {
          var tmpRow = [];
          $(this).filter(':visible').find('td').each(function() {
              if ($(this).css('display') != 'none') tmpRow[tmpRow.length] = formatData($(this).html());
          });
          row2CSV(tmpRow);
      });
      if (options.delivery == 'popup') {
          var mydata = csvData.join('\n');
          return popup(mydata);
      } else {
          var mydata = csvData.join('\n');
          return mydata;
      }
  
      function row2CSV(tmpRow) {
          var tmp = tmpRow.join('') // to remove any blank rows
          // alert(tmp);
          if (tmpRow.length &gt; 0 &amp;&amp; tmp != '') {
              var mystr = tmpRow.join(options.separator);
              csvData[csvData.length] = mystr;
          }
      }
      function formatData(input) {
          // replace " with “
          var regexp = new RegExp(/["]/g);
          var output = input.replace(regexp, "“");
          //HTML
          var regexp = new RegExp(/\&lt;[^\&lt;]+\&gt;/g);
          var output = output.replace(regexp, "");
          if (output == "") return '';
          return '"' + output + '"';
      }
      function popup(data) {
          var generator = window.open('', 'csv', 'height=400,width=600');
          generator.document.write('&lt;html&gt;&lt;head&gt;&lt;title&gt;CSV&lt;/title&gt;');
          generator.document.write('&lt;/head&gt;&lt;body &gt;');
          generator.document.write('&lt;textArea cols=70 rows=15 wrap="off" &gt;');
          generator.document.write(data);
          generator.document.write('&lt;/textArea&gt;');
          generator.document.write('&lt;/body&gt;&lt;/html&gt;');
          generator.document.close();
          return true;
      }
  };
  </code></pre>