Hope figured the question right. So, I have some radios, which my CMS loads as product options. On the same page I have an AJAX filter, which can load exactly the same radios to that exact place.
The trouble is, that I'm unable to change the total price with this dynamically created radios, but previous ones works just fine. Run the snippet for best understanding.
$('#add').on('click', function() {
if (!$('#price_3').length) {
$('#multiply').before('<input type="radio" name="radios" id="price_3" value="3"> <label for="price_3">Generated by AJAX</label> <br><br>');
$(this).remove();
}
})
$("input").bind("change keyup", function() {
var price = 100;
if ($('#price_1').is(':checked')) {
price += 100;
};
if ($('#price_2').is(':checked')) {
price += 200;
};
if ($('#price_3').is(':checked')) {
price += 300;
$(".total").append(" <- doesn't change the price");
$(".info").html("<br><br> Actually adds +300, but not live");
};
if ($('#multiply').is(':checked')) {
price *= 2;
};
$(".total").html(price);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="#" method="post">
<input type="radio" name="radios" id="price" value="0" checked>
<label for="price">I'm a base</label>
<br>
<input type="radio" name="radios" id="price_1" value="1">
<label for="price_1">Here by default</label>
<br>
<input type="radio" name="radios" id="price_2" value="2">
<label for="price_2">Here by default 2</label>
<br>
<input type="checkbox" name="multiply" id="multiply" value="multiply">
<label for="multiply">Multiply by 2</label>
<br>
<input type="button" id="add" value="Add a radio">
<br>
<span class="total">100</span>
<span class="info"></span>
</form>
Edit 1. The thing is not regarded to async ajax
or on
, because it actually does additions, but just doesn't show it on change
. I'm messing something with events.