title: How to get the dynamic table id value and to pass it to javascript function
body: <p>I need your help in getting the id value of the table and to pass the value to the a javascript function. I am having an image in the table and I want on click of it, the id of the table to be captured and to pass it to the javascript function. Here is the table code:</p>
  
  <pre><code>&lt;table class="tablesorter" id="detailsTable&lt;%=tableCounter%&gt;" width="80%"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;a href="javascript:fnExcelReport();"&gt;
  &lt;img border="0" src="../Images/excel_icon.png" alt="Export to Excel"&gt;&lt;/a&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>And the javascript function where I need to pass the id to it (in line no.7):</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function fnExcelReport()
  {
  
      var tab_text="&lt;table border='2px'&gt;&lt;tr bgcolor='#87AFC6'&gt;";
      var textRange; var j=0;
      tab = document.getElementById('detailsTable1'); // id of table
  
      for(j = 0 ; j &lt; tab.rows.length ; j++) 
      {     
          tab_text=tab_text+tab.rows[j].innerHTML+"&lt;/tr&gt;";
          //tab_text=tab_text+"&lt;/tr&gt;";
      }
  
      tab_text=tab_text+"&lt;/table&gt;";
      tab_text= tab_text.replace(/&lt;A[^&gt;]*&gt;|&lt;\/A&gt;/g, "");//remove if u want links in your table
      tab_text= tab_text.replace(/&lt;img[^&gt;]*&gt;/gi,""); // remove if u want images in your table
      tab_text= tab_text.replace(/&lt;input[^&gt;]*&gt;|&lt;\/input&gt;/gi, ""); // reomves input params
  
      var ua = window.navigator.userAgent;
      var msie = ua.indexOf("MSIE "); 
  
      if (msie &gt; 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer
      {
          txtArea1.document.open("txt/html","replace");
          txtArea1.document.write(tab_text);
          txtArea1.document.close();
          txtArea1.focus(); 
          sa=txtArea1.document.execCommand("SaveAs",true,"Say Thanks to Sumit.xls");
      }  
      else                 //other browser not tested on IE 11
          sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));  
  
      return (sa);
  }
  
  &lt;/script&gt;
  </code></pre>