title: Programmatically submitting a form while using AjaxForm
body: <p>I wanted to find a way to upload a single file*, in the background, have it start automatically after file selection, and not require a flash uploader, so I am trying to use two great mechanisms (jQuery.Form and JQuery MultiFile) together. I haven't succeeded, but I'm pretty sure it's because I'm missing something fundamental.</p>
  
  <p>Just using MultiFile, I define the form as follows...</p>
  
  <pre><code>&lt;form id="photoForm" action="image.php" method="post" enctype="multipart/form-data"&gt;
  </code></pre>
  
  <p>The file input button is defined as...</p>
  
  <pre><code>&lt;input id="photoButton" "name="sourceFile" class="photoButton max-1 accept-jpg" type="file"&gt;
  </code></pre>
  
  <p>And the Javascript is...</p>
  
  <pre><code>$('#photoButton').MultiFile({
      afterFileSelect: function(){
           document.getElementById("photoForm").submit();
      }
  });
  </code></pre>
  
  <p>This works perfectly. As soon as the user selects a single file, MultiFile submits the form to the server.</p>
  
  <hr>
  
  <p>If instead of using MultiFile, as shown above, let's say I include a Submit button along with the JQuery Form plugin defined as follows...</p>
  
  <pre><code> var options = {
    success: respondToUpload
   }; 
  
   $('#photoForm').ajaxForm(options);
  </code></pre>
  
  <p>... this also works perfectly. When the Submit button is clicked, the form is uploaded in the background.</p>
  
  <hr>
  
  <p>What I don't know how to do is get these two to work together. If I use Javascript to submit the form (as shown in the MultiFile example above), the form is submitted but the JQuery.Form function is not called, so the form does not get submitted in the background. </p>
  
  <p>I thought that maybe I needed to change the form registration as follows...</p>
  
  <pre><code>$('#photoForm').submit(function() {
   $('#photoForm').ajaxForm(options);
  });
  </code></pre>
  
  <p>...but that didn't solve the problem. The same is true when I tried .ajaxSubmit instead of .ajaxForm.</p>
  
  <p>What am I missing?</p>
  
  <ul>
  <li>BTW: I know it might sound strange to use MultiFile for single-file uploads, but the idea is that the number of files will be dynamic based on the user's account. So, I'm starting with one but the number changes depending on conditions.</li>
  </ul>