title: Order by clicking table header
body: <p>I have an form on my web site that a user can use to order a table of data by a column of choice.  Essentially it is similar to this:</p>
  
  <pre><code>&lt;form action="" method="post"&gt;
      &lt;select name="orderby"&gt;
          &lt;option value="col_1"&gt;Column 1&lt;/option&gt;
          &lt;option value="col_2"&gt;Column 2&lt;/option&gt;
          &lt;option value="col_3"&gt;Column 3&lt;/option&gt;
      &lt;/select&gt;
      &lt;input type="submit" value="Order By"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>It works well, but I want to update how this is done by allowing the user to click on the table column header instead.  My attempt to do this was to add the onclick event to my table headers and use Javascript to POST the same array back to the page.  In other words, <code>Array ( [orderby] =&gt; col_2 )</code> when Column 2 is clicked on will remain exactly the same.  This would preserve all of my other code.  Here is the change I made to my table headers:</p>
  
  <pre><code>&lt;table&gt;
    &lt;tr&gt;
      &lt;th onclick="post('col_1')"&gt;Column 1&lt;/th&gt;
      &lt;th onclick="post('col_2')"&gt;Column 2&lt;/th&gt;
      &lt;th onclick="post('col_3')"&gt;Column 3&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;A&lt;/td&gt;
      &lt;td&gt;B&lt;/td&gt;
      &lt;td&gt;C&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;B&lt;/td&gt;
      &lt;td&gt;C&lt;/td&gt;
      &lt;td&gt;A&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>And here is the Javascript I wrote:</p>
  
  <pre><code>&lt;script&gt;
  function post(clm) {
      $.post('mypage.php',{orderby:clm});
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>This isn't working.  Can anyone tell me what I need to change to get it to work?  Right now if I click on the table headers, the <code>$_POST</code> array remains empty.  (mypage.php is the same page that is calling the function.  I also tried it with nothing between the single quotes, like you would with the form action attribute, but it didn't work that way either.)  </p>