Passing variables from a html file to an external jQuery function
<p>I've been scouring the internet trying to find a way to do this with jQuery.  My situation is this, I have a tablesorter function (using the jQuery plugin tablesorter) in an external scripts.js file as follows:</p>

<pre><code>$(function() {
  $(aTable).tablesorter({ 
        // Go through each column and sort data according to type of data in the column
    });
 });
</code></pre>

<p>In my html file I have it declared in my head as follows</p>

<pre><code>&lt;script type="text/javascript" src="starterkit/jquery-1.3.2.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="starterkit/jquery.tablesorter.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="starterkit/scripts.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
var aTable = $("#myTable");
var columns = $("#myTable tbody th:").length;
&lt;/script&gt;
</code></pre>

<p>What I want to do is pass the aTable and columns variables to the external function and use a for loop to cycle through each column to determine <strong>a)</strong> should the column be sorted or not and <strong>b)</strong> if it is to be sorted, what kind of data is in the column? Add a special parser depending on this data, i.e. if the column contains a date, add a date parser, etc.  I'm completely stuck, any hints are appreciated.</p>

<p><strong>UPDATE</strong></p>

<p>@ Chad Bird, here is the complete code as I originally had it for one table instance, I've also included the sample table I'm working with:</p>

<pre><code>$(function() {
  $(aTable).tablesorter({ 
        // pass the headers argument and passing a object 
        headers: {
         // place usLongDate parser in date column for proper sorting
   2 : { sorter: "usLongDate"  },
            // assign the fourth column (we start counting zero) 
            3: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            }, 
            // assign the eighth column (we start counting zero) 
            7: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            } 
        } 
    });
 });
</code></pre>

<p>Sample Table</p>

<pre><code>&lt;table id="myTable" summary="Table is used to list available workshops"  cellspacing="0"&gt;
      &lt;thead&gt;
       &lt;tr&gt;
        &lt;th&gt;&lt;a rel = "Header" href="#" title="Sort column in decending order" class="sort-down"&gt;Title&lt;/a&gt;&lt;/th&gt;
        &lt;th&gt;&lt;a rel = "Header" href="#" title="Sort column in ascending order" class="sort-down"&gt;Instructor&lt;/a&gt;&lt;/th&gt;
        &lt;th&gt;&lt;a rel = "Header" href="#" title="Sort column in decending order" class="sort-up"&gt;Date&lt;/a&gt;&lt;/th&gt;
        &lt;th id="1"&gt;Start/End&lt;/th&gt;
        &lt;th&gt;&lt;a rel = "Header" href="#" title="Sort column in decending order" class="sort-up"&gt;Seats Available&lt;/a&gt;&lt;/th&gt;
        &lt;th&gt;&lt;a rel = "Header" href="#" title="Sort column in decending order" class="sort-up"&gt;Enrolled&lt;/a&gt;&lt;/th&gt;
        &lt;th&gt;&lt;a rel = "Header" href="#" title="Sort column in decending order" class="sort-up"&gt;Pre-Requisites&lt;/a&gt;&lt;/th&gt;
        &lt;th id="1"&gt;Workshop Actions&lt;/th&gt;
       &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
       &lt;tr&gt;
        &lt;td&gt;Basic Economics for CEOs&lt;/td&gt;
        &lt;td&gt;George Washington&lt;/td&gt;
        &lt;td&gt;March 2, 2009&lt;/td&gt;
        &lt;td&gt;9:00am - 11:00am&lt;/td&gt;
        &lt;td&gt;0 / 20&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Details&lt;/td&gt;
       &lt;/tr&gt;
       &lt;tr&gt;
        &lt;td&gt;Intro. to Psychology&lt;/td&gt;
        &lt;td&gt;Jimi hendrix&lt;/td&gt;
        &lt;td&gt;March 6, 2009&lt;/td&gt;
        &lt;td&gt;10:00am 12:00pm&lt;/td&gt;
        &lt;td&gt;11 / 15&lt;/td&gt;
        &lt;td&gt;Enrolled&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Details&lt;/td&gt;
       &lt;/tr&gt;
&lt;tr&gt;
        &lt;td&gt;Improving the Workplace&lt;/td&gt;
        &lt;td&gt;Dr. Manhattan&lt;/td&gt;
        &lt;td&gt;March 20, 2009&lt;/td&gt;
        &lt;td&gt;3:00pm - 4:30pm&lt;/td&gt;
        &lt;td&gt;12 / 18&lt;/td&gt;
        &lt;td&gt;Enrolled&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Details&lt;/td&gt;
       &lt;/tr&gt;
       &lt;tr&gt;
        &lt;td&gt;Music appreciation&lt;/td&gt;
        &lt;td&gt;Tupac Shakur&lt;/td&gt;
        &lt;td&gt;March 21, 2009&lt;/td&gt;
        &lt;td&gt;10:30am - 12:30pm&lt;/td&gt;
        &lt;td&gt;20 / 25&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;Details&lt;/td&gt;
       &lt;/tr&gt;
      &lt;/tbody&gt;
     &lt;/table&gt;
</code></pre>

<p>Basically, I'm trying to make it so anyone who implements this only needs to worry about giving a consistent name to all tables, i.e. all tables are named "myTable".  And the function takes care of counting the number of columns, determining (by searching for id="1" in the table header) whether to set the column to sorter: false, or, if it does need to be sorted, determine the type of data that is in the column, i.e. if the column contains dates, then add the usLongDate parser, etc.</p>
