Please refer to images
I am trying to code a "+" button that when you click on it, my Jquery dynamically adds another size input field
The problem is that when it is inside the "form" tag and I click on the button, it appears for 1 second and disappears automatically. When I remove the "form" tag, it works as expected and does not disappear.
Here is my the part of my code for the size input causing the problem:
<form method="POST" action="addProduct.php">
<div class="col-lg-4 topmargin">
<span><h4>Size</h4></span>
<table class="table borderless sizeTable" id="dynamic_price" >
<tr>
<td> <input class="form-control "type="text" name="size[]" placeholder="200 ml" size="100%"> </td>
<td><button class="btn btn-primary" name="addSize" id="addSize">+</button></td>
</tr>
</table>
</div>
</form>
Here is JQuery:
<script>
$("#addSize").click(function(){
$('.sizeTable tbody tr:last').after('<tr><td> <input class="form-control "type="text" name="size[]" placeholder="9.99" size="100%"> </td><td><button class="btn btn-danger" name="removeSize">-</button></td></tr>');
});
</script>
How can I make it work inside my form?