title: JQuery POSTing with buttons values, returning input?
body: <p>Hey guys and gals I'm having some major issues trying to get my application to work. I've been trying to hack through this and am missing the very first part which is sending the correct input value (button value) to get the ball rolling, I'm sure this is something simple but I've been having an issue getting it working. I'd appreciate it if someone could pick out the error(s) to help me along.</p>
  
  <p>This is extremely easy to do in PHP, but since this is a standalone offline 
  app I cannot use PHP =( I need to do all my fetching and parsing in JQuery
  or Javascript....</p>
  
  <p>We start with a very basic form with some buttons that have unique values.</p>
  
  <pre><code>&lt;form&gt;
  
  &lt;fieldset&gt;
  &lt;legend&gt;Select Orders&lt;/legend&gt;
  
  &lt;table id='master'&gt;&lt;/table&gt;
  
    &lt;/div&gt; &lt;!-- end input1 --&gt;
      &lt;div&gt;
       &lt;button name="select" type="submit" id="btnLoad" value="load"&gt;Refresh&lt;/button&gt;
       &lt;button name="select" type="submit" id="btnJson" value="down"&gt;Download JSON&lt;/button&gt;
       &lt;button name="select" type="submit" id="btnView" value="view"&gt;View/Enter&lt;/button&gt;
      &lt;/div&gt;
  &lt;/fieldset&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>which triggers this function</p>
  
  <pre><code>$(function() {
      $("form").submit(function() {
  
          /* what obj are we recieving?
          $.each($(this), function(index, obj) {
              console.log('Index: ' + index + ' Obj: '+ obj);
              // returns this B/S: Index: 0 Obj: [object HTMLFormElement]
          });
          */
  
          // $this.button.val() never makes it through?
          queryJsonServer($(this), "class/");
          return false;
      });
  });
  </code></pre>
  
  <p>I've tried things like</p>
  
  <pre><code>var button = $(this).attr("value");
  var button = $('button').attr("value"); // ends up with the first buttons value,
                                          // but never the selected or $(this).val()
  
  $('button').click(function() {          // which WILL console.log the buttons val,
    console.log($(this).val());           // but will not let me turn it into a var?
    return false;                         // ALSO this looks like it only reads the
  });                                     // value the SECOND click?
  </code></pre>
  
  <p>The <strong>Mission</strong> here is to send the buttons value as a $_POST type over to a parser which will return the appropriate JSON array to be parsed, or to be stored in a Local SQLite DB.</p>
  
  <p>Either way, here's the full code of the page, could someone please give me a hand, or if I need to clarify please let me know.</p>
  
  <pre><code>&lt;?php 
      ini_set('display_errors', 1);
      error_reporting(E_ERROR | E_PARSE);
      var_export($_POST);
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en-US"&gt;
      &lt;head&gt;
       &lt;title&gt; &lt;/title&gt;
  
       &lt;script src='http://www.google.com/jsapi'&gt;&lt;/script&gt;
       &lt;script&gt; google.load('jquery', '1.7.1'); &lt;/script&gt;
  
       &lt;script&gt;
          $(function(){
              $("form").submit(function() 
              {
  
                  /* what obj are we recieving?
                  $.each($(this), function(index, obj) {
                      console.log('Index: ' + index + ' Obj: '+ obj);
                      // returns this B/S: Index: 0 Obj: [object HTMLFormElement]
                  });
                  */
  
                  $('button').click(function() {
                      var state = $(this).val();
                      return true;
                  });
  
                  // state is undefined. L29
                  console.log(state);
  
                  // $this.button.val() never makes it through?
                  queryJsonServer($(this), state, "class/");
                  return false;
              });
  
              // query json server for
              function queryJsonServer(form, state, path) 
              {
  
                  // on first return or refresh inputs will be returrned
                  var view    = $('input[name="orders"]:checked').val();
                  var url     = path + "json.php?" + state; // status = button.val()
                  var state   = $(this).attr("value"); // ends up class/json.php?undefined
  
                  // we have data, lets post to json parser and 
                  $.getJSON(url, view, function(data) 
                  {
                       $('form').unbind('submit').trigger('submit');
  
                      var items = [];
  
                          switch(state)
                          {
                              case 'load' : 
  
                                  $.each(data, function(index, obj) { 
                                      items.push('&lt;tr&gt;');
                                      $.each(obj, function(key, val) { 
                                        items.push((key == "report_number") 
                                        ? '&lt;td class="check" &gt;&lt;input type="checkbox" name="' + val + '" /&gt;&lt;/td&gt;&lt;td&gt;&lt;label class="caps" for="'+ key +'"&gt;'+ key.replace("_", " ") +'&lt;/label&gt;&lt;input disabled="disabled" type="text" id="' + key + '" value="' + val + '" /&gt;&lt;/td&gt;' 
                                        : '&lt;td&gt;&lt;label class="caps" for="'+ key +'"&gt;'+ key.replace("_", " ") +'&lt;/label&gt;&lt;input disabled="disabled" type="text" id="' + key + '" value="' + val + '" /&gt;&lt;/td&gt;')
                                      }); 
                                      items.push('&lt;/tr&gt;');
                                  });
  
                                  $('&lt;div/&gt;', {
                                      'class': 'jsonOutput',
                                      html: items.join('')
                                    }).appendTo('#master');
  
                                break;
  
                              case 'down' : 
                                // populate SQLite Database
                                break;
  
                              case 'view' : 
  
                                  $.each(data, function(index, obj) { 
                                      items.push('&lt;tr&gt;');
                                      $.each(obj, function(key, val) { 
                                        items.push('&lt;td&gt;&lt;label class="caps" for="'+ key +'"&gt;'+ key.replace("_", " ") +'&lt;/label&gt;&lt;input disabled="disabled" type="text" id="' + key + '" value="' + val + '" /&gt;&lt;/td&gt;')
                                      }); 
                                      items.push('&lt;/tr&gt;');
                                  });
  
                                  $('&lt;div/&gt;', {
                                      'class': 'jsonOutput',
                                      html: items.join('')
                                    }).appendTo('#master');
  
                                break;
  
                              default: 
                                return false; 
                                break;
                          }
  
                  });
              }
          });
       &lt;/script&gt;
  
      &lt;style type="text/css"&gt;
       p, ul {width:100%; text-align:left;font-size:80%;}
       .reports_box {width:auto; padding:25px 20px 20px 20px;border:1px solid #91bce6;background-color:#eff5fb;}
       .inputs {width:300px; font-size:15px;padding:5px;}
       .check input {padding:0 !important;}
       .caps {text-transform:capitalize;}
       #reports_list td, #reports_list tr {padding:10px 0 10px 2px;color:#34567b;}
      &lt;/style&gt;
  
      &lt;/head&gt;
  
   &lt;body&gt;
  
  
  &lt;div class="reports_box"&gt;
      &lt;form id='submit'&gt;
  
      &lt;fieldset&gt;
      &lt;legend&gt;Select Orders&lt;/legend&gt;
  
      &lt;table id='master'&gt;&lt;/table&gt;
  
        &lt;/div&gt; &lt;!-- end input1 --&gt;
          &lt;div&gt;
           &lt;button name="select" type="submit" id="btnLoad" value="load"&gt;Refresh&lt;/button&gt;
           &lt;button name="select" type="submit" id="btnJson" value="down"&gt;Download JSON&lt;/button&gt;
           &lt;button name="select" type="submit" id="btnView" value="view"&gt;View/Enter&lt;/button&gt;
          &lt;/div&gt;
      &lt;/fieldset&gt;
  
      &lt;/form&gt;
  &lt;/div&gt; &lt;!-- end reports_box --&gt;
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>