JSFiddle - React, Tailwind, and code Playground
HTML
Check if
<input
type="checkbox"
id="IRF"
name='IRF'
/>
<br>
<select name="SPECIAL" id="SPECIAL">
<option>Please Select</div>
<option
data-name="Animal Friend"
data-img="/images/img/AnimalFriend.png"
data-price="30"
value="1">Animal Friend</option>
<option
data-name="Aquaculture"
data-img="/images/img/Aquaculture.png"
data-price="25"
value="2">Aquaculture</option>
<option
data-name="Protect Our Oceans"
data-img="/images/img/ProtectOurOceans.png"
data-price="20"
value="3">Protect Our Oceans</option>
</select>
<div id="totalPrice"></div>
<!-- Modal -->
<div class="modal fade" id="modal_special" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Specialty Plate</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary accept">Accept</button>
</div>
</div>
</div>
</div>
<div id="totalPrice"></div>
JavaScript
var specialFee = 0;
$(function(){ //added by me
$('#IRF').click(function(){
calculateTotal();
});
});
function initialRegFee()
{
var initialFee=0;
var theForm = document.forms["form"];
var iRF = document.getElementById('IRF');
if(iRF.checked==true)
{
initialFee=225;
}
return initialFee;
}
function calculateTotal()
{
var titleFees = initialRegFee();
titleFees += specialFee;
var divobj = document.getElementById('totalPrice');
divobj.style.display='block';
divobj.innerHTML = "Estimated Transfer Fees $"+titleFees;
}
function hideTotal()
{
var divobj = document.getElementById('totalPrice');
divobj.style.display='none';
}
$(function() {
$('#SPECIAL').on('change', function() {
if ($('option:selected', this).is('[data-img]')) {
$('#modal_special').find('.modal-title').html($('option:selected', this).data('name'));
$('#modal_special').find('.modal-body').html('')
.append('<img alt="coming soon" src="' + $('option:selected', this).data('img') + '"/><br/><br/> Would you like to add this license plate for: $' + $('option:selected', this).data('price') + ' ?')
.end().modal('show');
}
});
$('.accept').on('click',function() {
specialFee = $('option:selected').data('price');
calculateTotal();
$('#modal_special').modal('hide');
});
});