I have a link aimed to '/FridgeTemperatureRoute' and a checkbox. Purpose of the checkbox is to show the user whether the check has been done or not.
<div class="row">
<div class="col">
<a id="FridgeTemperatureBtn" href="/FridgeTemperatureRoute">Fridge and Freezer Temperature</a>
</div>
<div class="col">
<input id="FridgeTemperatureCheckBox" type="checkbox" name="" value="" disabled {{fridgeFreezerTemperatureReturnObj}}>
</div>
</div>
Summary of code
You'll see this line {{fridgeFreezerTemperatureReturnObj}} - this is from Node JS server, which determines whether the checkbox is ticked or not.
Jquery, Javascript and Bootstrap Model
Next, I am aiming to open a bootstrap model on user click, but only if the checkbox is ticked. If the user clicks and the checkbox is checked, then open a bootstrap model asking whether to continue to the href or simply cancel rendering the next page.
<!-- Modal confirm -->
<div class="modal" id="confirmModal" style="display: none; z-index: 1050;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body" id="confirmMessage">
<p>You have already completed this check, do you want to do it again?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="confirmOk">Ok</button>
<button type="button" class="btn btn-default" id="confirmCancel" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
if(document.getElementById('FridgeTemperatureCheckBox').checked){
$('#FridgeTemperatureBtn').attr('data-toggle', 'modal');
$('#FridgeTemperatureBtn').attr('data-target', '#confirmModal');
document.getElementById('FridgeTemperatureBtn').addEventListener('click', function(e){
$('#confirmOk').click(function(){
window.location.href = '/FridgeTemperatureRoute';
});
});
}
</script>
Summary
I have it working - but I believe it can be simplified. Just looking for some reviews and where I can improve on :)