Problem using jQuery to add a cloned form dynamically

Problem using jQuery to add a cloned form dynamically

Hi everyone,i have a form and an add new form link that adds a multiple form like the first one dynamically, and inside the form there is an author text input with also a link to add dynamically multiple author's input. 

the problem is that when i add multiple forms..only in the first form i can add multiple authors, and not in the other forms. and the author's text inputs are added outside the first form.

Can somebody help me identifying the probleme in my code, please.
Also can somebody informe me how ca i add a delete link to delete each form. Thank you.
Here's my code :
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  7. <script>
  8. $(document).ready(function() {

  9. var MaxInputs       = 8; //maximum input boxes allowed
  10. var InputsWrapper   = $("#InputsWrapper"); //Input boxes wrapper ID
  11. var AddForm       = $("#AddMoreForm"); //Add button ID
  12. var AddAuthor       = $("#AddMoreAuthor"); //Add button ID

  13. var x = InputsWrapper.length; //initlal text box count
  14. var FieldCount=1; //to keep track of text box added

  15. $(AddForm).click(function (e)  //on add input button click
  16. {
  17.         if(x <= MaxInputs) //max input box allowed
  18.         {
  19.             FieldCount++; //text box added increment
  20.             //add input box
  21.             $(InputsWrapper).append('<div><form style="border:3px double #F7730E;"  name="forms[]" id="form_'+ FieldCount +'" >Titre:<input type="text" name="Titre[]"><div>Auteur:<input type="text" name="myAuteur[]" id="Auteur_1" value="Auteur 1" /><a href="#" class="removeclass">&times;</a></div><a href="#" id="AddMoreAuthor" class="btn btn-info">Add More Auteur</a></div><input type="submit" value="Ajouter publication" /></form></div>');
  22.             x++; //text box increment
  23.         }
  24. return false;
  25. });

  26. //button d'ajout d'auteur
  27. $(AddAuthor).click(function (e)  //on add auteur input button click
  28. {
  29.         if(x <= MaxInputs) //max input box allowed
  30.         {
  31.             FieldCount++; //text box added increment
  32.             //add input box
  33.             $(InputsWrapper).append('<div>Auteur:<input type="text" name="myAuteur[]" id="Auteur_'+ FieldCount +'" value="Auteur '+ FieldCount +'"/><a href="#" class="removeclass">&times;</a></a></div>');
  34.             x++; //text box incrementb 
  35.         }
  36. return false;
  37. });

  38. $("body").on("click",".removeclass", function(e){ //user click on remove text
  39.         if( x > 1 ) {
  40.                 $(this).parent('div').remove(); //remove text box
  41.                 x--; //decrement textbox
  42.         }
  43. return false;
  44. }) 

  45. });
  46. </script>
  47. </head>

  48. <body>

  49. <a href="#" id="AddMoreForm" class="btn btn-info">Add More Form</a>
  50. <div id="InputsWrapper">
  51. <div><form style="border:3px double #F7730E;" name="forms[]" id="form_1" >Titre:<input type="text" name="Titre[]">
  52. <div>Auteur:<input type="text" name="myAuteur[]" id="Auteur_1" value="Auteur 1"><a href="#" class="removeclass">&times;</a><a href="#" id="AddMoreAuthor" class="btn btn-info" onclick="">Add More Authors</a></div>
  53. <input type="submit" value="Ajouter publication" />
  54. </form></div>

  55. </div>


  56. </body>
  57. </html>