My main goal is to get the amount that whatever the user has keyed in the textbox if the checkbox next to it is checked and sum all amount of the checked checkboxes.
But the current problem that I'm facing is, I can't even get the checkbox value after it is appended.
How to solve this problem? Jsfiddle link here
$('#add_exercise').on('click', function() {
$('#exercises').append('<div class="exercise"><input type="text" name="amount"><input type="checkbox" name="exercise[]" class="boxes"><button class="remove">x</button></div>');
return false; //prevent form submission
});
$('#exercises').on('click', '.remove', function() {
$(this).parent().remove();
return false; //prevent form submission
});
$('.boxes').on('change', function() {
console.log('qwe')
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form method="post" action="#">
<label>Exercises</label>
<fieldset id="exercises">
<div class="exercise">
<input type="text" name="amount" value="">
<input type="checkbox" name="exercise[]" class="boxes"><button class="remove">x</button>
</div>
</fieldset>
<button id="add_exercise">add exercise</button>
</form>