Page reloading with e.preventDefault + unable to appen more than once

Page reloading with e.preventDefault + unable to appen more than once

Hello,


I am struggling with 2 problems, the first one is that I can only run the "appen" function once, and then even if I keep clicking on the function, no more than 1 click of data is added(at least the external file is pulled correctly).


My second problem is that when I try to delete the appended data, the page delete the 2 fields from the external file but refresh the page while doing it

Any idea why I am experiencing both issues please?

Here is my code:


  1.         <div class="col-md-2"></div>
  2.         <div class="col-md-8">
  3.         <form action="" method="post" class="form">
  4.         <div class="form-group">
  5.         <label for="variantgroupname">Variant Group Name (ie: Size)</label>
  6.         <input type="text" class="form-control" placeholder="Variant Group name" name="variant_group_name">
  7.         </div>
  8.         <br> <br> <br>
  9.         <div class="form-group">
  10.         <label for="subvariantname">Sub Variant Name (ie: Small,Medium,Large)</label>
  11.         <input type="text" class="form-control" placeholder="Sub Variant Name" name="sub_variant_name[]">
  12.         </div>

  13.         <div class="form-group">
  14.             <label for="linktotoppinglist">Link Topping List</label>
  15.             <select name="toppinglist[]" class="form-control">
  16.         <?php
  17.             $stmt = $conn->prepare("SELECT id,value FROM vat_rates ORDER BY id");
  18.             $stmt->bind_result($id,$value);
  19.             $stmt->execute();
  20.             $stmt->store_result();
  21.             if($stmt->num_rows() > 0){

  22.             while ($stmt->fetch()) {
  23.             $s = "";
  24.             if(isset($_POST['selectvat']) && ($_POST['selectvat'] == $id))
  25.             {
  26.             $s = " selected";
  27.             }
  28.             echo "<option value='".$id."'".$s.">".$value."</option>";
  29.             }
  30.             }
  31.             $stmt->free_result();
  32.             $stmt->close();
  33.          ?>
  34.         </select>
  35.         </div>
  36.         <div class="input_fields_wrap">
  37.         <div class="load_fields"></div>

  38.         <button class="btn btn-success" id="add_field_button">Add More Fields</button>
  39.         <button class="btn btn-danger remove_field" id="#remove_field">Remove Field</button>
  40.         </div>
  41.         </form>
  42.         </div>
  43.         <div class="col-md-2"></div>





  1. <script>
  2.     $(document).ready(function() {
  3.     var max_fields      = 15; //maximum input boxes allowed
  4.     var wrapper         = $(".input_fields_wrap"); //Fields wrapper
  5.     var add_button      = $("#add_field_button"); //Add button ID

  6.     var x = 1; //initlal text box count
  7.     $(add_button).click(function(e){ //on add input button click
  8.         e.preventDefault();
  9.         if(x < max_fields){ //max input box allowed
  10.             x++; //text box increment
  11.         $('.load_fields').load('index.php?page=admin_add_variant_group_append.php');
  12.         }
  13.     });

  14.     $(wrapper).on("click","#remove_field", function(e){
  15.         $(this).parent('div').remove(); x--;
  16.         e.preventDefault();
  17.     })
  18. });
  19. </script>





external file:
  1.         <div class="form-group">
  2.         <label for="subvariantname">Sub Variant Name (ie: Small,Medium,Large)</label>
  3.         <input type="text" class="form-control" placeholder="Sub Variant Name" name="sub_variant_name[]">
  4.         </div>

  5.         <div class="form-group">
  6.             <label for="linktotoppinglist">Link Topping List</label>
  7.             <select name="toppinglist[]" class="form-control">
  8.         <?php
  9.             $stmt = $conn->prepare("SELECT vat_id,vat_value FROM vat_rates ORDER BY vat_id");
  10.             $stmt->bind_result($vat_id,$vat_value);
  11.             $stmt->execute();
  12.             $stmt->store_result();
  13.             if($stmt->num_rows() > 0){

  14.             while ($stmt->fetch()) {
  15.             $s = "";
  16.             if(isset($_POST['selectvat']) && ($_POST['selectvat'] == $vat_id))
  17.             {
  18.             $s = " selected";
  19.             }
  20.             echo "<option value='".$vat_id."'".$s.">".$vat_value."</option>";
  21.             }
  22.             }
  23.             $stmt->free_result();
  24.             $stmt->close();
  25.          ?>
  26.         </select>
  27.         </div>

Thank you.