i have a website where i have a form, the form has 3 fields which can be addedd multiple times on click, my code is like below:
$(document).ready(function() {
var max_fields = 10;
var wrapper = $(".container1");
var add_button = $("#niy");
var x = 1;
$(add_button).click(function(e) {
e.preventDefault();
if (x < max_fields) {
x++;
$(wrapper).append('<div class="col-lg-4 col-sm-6"><div class="mb-4"><label for="client_type">Service Type</label><input type="text" class="form-control" id="client_type" required name="service[]"></div></div><div class="col-lg-4 col-sm-6"><div class="mb-4"><label for="client_type">Price</label><input type="text" class="form-control" id="client_type" required name="price[]"></div></div><div class="col-lg-4 col-sm-6"><div class="mb-4"><label for="client_type">Total</label><input type="text" class="form-control" id="total" required name="total[]"></div></div>'); //add input box
} else {
alert('You Reached the limits')
}
});
$(wrapper).on("click", ".delete", function(e) {
e.preventDefault();
$(this).parent('div').remove();
x--;
})
});
$('input[name="price[]"]').change(function() {
$('input[name="total[]"]').val($(this).val());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row container1">
<div class="col-lg-4 col-sm-6">
<!-- Form -->
<div class="mb-4">
<label for="client_type">Service Type</label>
<input type="text" class="form-control" id="client_type" required name="service[]">
</div>
</div>
<div class="col-lg-4 col-sm-6">
<!-- Form -->
<div class="mb-4">
<label for="client_type">Price</label>
<input type="text" class="form-control" id="client_type" required name="price[]">
</div>
</div>
<div class="col-lg-4 col-sm-6">
<!-- Form -->
<div class="mb-4">
<label for="client_type">Total</label>
<input type="text" class="form-control" id="client_type" required name="total[]">
</div>
</div>
</div>
<a id="niy" class="btn btn-warning" style="color:white">Add New Service Field
<span style="font-size:16px; font-weight:bold;">+ </span>
</a>
i want the total field to show the value from its respective price field, however here only first row does that, can anyone please tell me how to fix this, thanks in advance