im trying change price of dropdwon (select option) on radio button checked.
when user will selection option from dropdown and checked NO carpet or Yes Carpet price amount will change according to user input
<form action="" method="post">
<div class="row">
<div class="col-md-4 mb-3">
<select name="cars" id="form-select" class="form-select carsOption">
<option value="select your option">Select your option</option>
<option data-price="350" data-carpet="410" value="1 bed 1 bath" id="1">1 bed 1 bath</option>
<option data-price="350" data-carpet="410" value="2 bed 1 bath" id="2">2 bed 1 bath</option>
<option data-price="350" data-carpet="500" value="3 bed 1 bath" id="3">3 bed 1 bath</option>
<option data-price="400" data-carpet="500" value="3 bed 2 bath" id="4">3 bed 2 bath</option>
<option data-price="454" data-carpet="600" value="4 bed 2 bath" id="5">4 bed 2 bath</option>
<option data-price="500" data-carpet="645" value="5 bed 2 bath" id="6">5 bed 2 bath</option>
</select>
</div>
<div class="col-md-2 mb-3">
<label for="nocarpet">
<input type="radio" name="clean" class="radioClean form-check-input" id="nocarpet" value="nocarpet">
No Carpet
</label>
</div>
<div class="col-md-2 mb-3">
<label for="yescarpet">
<input type="radio" name="clean" class="radioClean form-check-input" id="yescarpet" value="yescarpet">
Yes Carpet
</label>
</div>
<div class="col-md-3 mb-3">
<!-- <input type="text" name="price" class="form-control" id="markup"> -->
<span class="product-price" itemprop="price" id="markup"></span>
</div>
</div>
</form>
Jquery
$('input:radio[name="clean"]').change(
function(){
if ($(this).is(':checked') && $(this).val() == 'nocarpet') {
var basePrice = +($('#markup').html()).replace(/[^0-9\.]+/g,"");
$(".form-select").change(function() {
newPrice = basePrice;
$(".form-select option:selected").each(function() {
newPrice = +$(this).attr('data-price')
});
$("#markup").html("$" + newPrice.toFixed(2));
});
}
});
$('input:radio[name="clean"]').change(
function(){
if ($(this).is(':checked') && $(this).val() == 'yescarpet') {
var basePrice = +($('#markup').html()).replace(/[^0-9\.]+/g,"");
$(".form-select").change(function() {
newPrice = basePrice;
$(".form-select option:selected").each(function() {
newPrice = +$(this).attr('data-carpet')
});
$("#markup").html("$" + newPrice.toFixed(2));
});
}
});
when select option from dropdown when 1st radio button is selected price changes according but when i select second radio button (yes carpet) price does changes, i have again select option from drop down for price change… on shift radio button price doesn’t after shifting radio button i have to choose option from dropdown again for price to works