title: Using Jquery, How do I submit a form that was created with AJAX?
body: <p>I have a 2 part form.</p>
  
  <p>The 1st form is submitted via $.post and (if all goes right), is replaced by a dynamically generated form from php.  The idea behind this being that the 1st form creates an entry and the number of related images for said item.  A new form is generated to upload said images.</p>
  
  <p>My problem is that my newly generated form is not getting processed.  If submit the form via the old  onClick="" function, the dynamically generated file fields are ignored.</p>
  
  <p>I'm pretty new to Jquery/AJAX, so I may not be doing this correctly, but how can I get Jquery to pay attention to my 2nd (dynamically generated) form?</p>
  
  <p>1st Form:</p>
  
  <pre><code>&lt;form name="addinv" id="addinv" action="admin_process.php" method="post"&gt;
            &lt;fieldset&gt;
              &lt;legend&gt;Add Inventory&lt;/legend&gt;
              &lt;input type="hidden" name="actiontotake" id="actiontotake" value="none" /&gt;
              &lt;table width="400" border="0"&gt;
                &lt;caption&gt;
                Add Inventory Form Layout Table
                &lt;/caption&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Price&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="price" id="price" tabindex="1" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Manufacturer&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="mfg" id="mfg" tabindex="2" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Model&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="model" id="model" tabindex="3" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Serial Number&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="sn" id="sn" tabindex="4" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Year&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="year" id="year" tabindex="5" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Size (Dimensions)&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="dimensions" id="dimensions" tabindex="6" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Bedrooms&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="beds" id="beds" tabindex="7" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Bathrooms&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="baths" id="baths" tabindex="8" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Range Type&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="range" id="range" tabindex="9" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Siding Type&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="siding" id="siding" tabindex="10" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Roof Type&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="roof" id="roof" tabindex="11" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Furnace Type&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="furnace" id="furnace" tabindex="12" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Features &amp;amp; Benefits&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;textarea name="fandb" id="fandb" tabindex="13"&gt;&lt;/textarea&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;strong&gt;Number of Pictures&lt;/strong&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="picnum" id="dimensions" tabindex="14" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td colspan="2" align="center"&gt;&lt;input name="addinventorybutton" id="addinventorybutton" type="submit" value="Add Home" tabindex="15"/&gt;&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/table&gt;
            &lt;/fieldset&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>Jquery handler:</p>
  
  <pre><code>$(document).ready(
      function(){
          $("#addinventorybutton").click(
              function(){
                 $("#actiontotake").val("Add Home");
                 var dta = $("#addinv").serialize();
                             $.post("admin_process.php",dta,function(data){
                     $("div#form").html(data);
                             });
              return false;
          });
                      $("#addnewpicturesbutton").click(
              function(){
              $("#actiontotake").val("Add Picture");
              AddPic();
              return false;
          });
      });
  </code></pre>
  
  <p></p>
  
  <p>2nd Form (via PHP &amp; AJAX call):</p>
  
  <pre><code>&lt;form name="addpictures" id="addpictures" enctype="multipart/form-data" method="post" action="admin_process.php"&gt;
          &lt;fieldset&gt;&lt;legend&gt;Add Associated Images&lt;/legend&gt;
          &lt;?php 
              for($i=0;$i&lt;$pics;$i++)
              {
                  echo("&lt;input type='file' name='pic".$i."' /&gt;&lt;br /&gt;\n");
              }
              ?&gt;
              &lt;input type="hidden" name="actiontotake" id="actiontotake" value="none" /&gt;
              &lt;input type="hidden" name="inventory_id" id="inventory_id" value="&lt;?php echo $newid; ?&gt;"&gt;
              &lt;input type="button" name="addnewpicturesbutton" id="addnewpicturesbutton" value="Add Pictures to new home"&gt;
              &lt;/fieldset&gt;
              &lt;/form&gt;
  </code></pre>