title: Create and submit a form dynamically via AJAX
body: <p>I have a shoutbox with an edit link. When clicked (the code below) it prompts to edit the post and then on submit it dynamically creates a form and submits the form to another page to process it.</p>
  
  <p>Originally the other page would process it and redirect back to the page that the user was on. However I've changed the way my shoutbox is displayed.</p>
  
  <p>What I want to do is to dynamically create the form as such but then instead of submitting it to the other page (where it actually takes me in my browser to the action page, I want to submit the form with AJAX so that I never leave the page I'm currently on.</p>
  
  <p>So basically I could be on the home page, edit a post and then when I confirm the edit, I should remain on the home page and then the form will be processed via AJAX in the background and the shoutbox container will be reloaded (instead of the page itself).</p>
  
  <pre><code>$('span.edit a').click(function (event) {
      event.preventDefault();
      var id = $(this).attr('id');
      var url = $(this).attr('href');
      var new_post = prompt('', $('#shoutbox_comment_' + id).html());
  
      if (new_post != '' &amp;&amp; new_post != null &amp;&amp; new_post != $('#shoutbox_comment_' + id).html()) {
          var form = $(
              '&lt;form action="' + url + '" method="post"&gt;' +
              '&lt;input type="hidden" name="comment" value="' + new_post + '"&gt;' +
              '&lt;input type="hidden" name="id" value="' + id + '"&gt;' +
              '&lt;input type="submit"&gt;' +
              '&lt;/form&gt;');
          $('body').append(form);
          $(form).submit();
  
          $('#shoutbox_container').load('../../website/inc/views/shoutbox/shoutbox.php?p=' + $(this).parent().attr('id'));
      } else if (new_post != null) {
          alert("Your post could not be edited. Make sure that your comment is not blank and that you've made changes.");
      }
  });
  </code></pre>
  
  <p>I've already gotten the AJAX just fine for the delete link but because of the form for the post data I'm having issues figuring out how to submit this in the background.</p>