What I have is a house plan that had javascript overlaid divs.
I want to create a function that calculates figures based on whether these div ids are displayed or not and then return that answer.
Here is the JSFiddle https://jsfiddle.net/offtkdqk/
function calculate_total(ppa, cpa, cpo, gar) {
var tot_price = 279500;
var a = document.getElementById(ppa);
if (a.style.display == 'block') var ppa_tot = 1000;
var b = document.getElementById(cpa);
if (b.style.display == 'block') var cpa_tot = 5000;
var c = document.getElementById(cpo);
if (c.style.display == 'block') var cpo_tot = 6000;
var d = document.getElementById(gar);
if (d.style.display == 'block') var gar_tot = 9000;
var estimate = tot_price + ppa_tot + cpa_tot + cpo_tot + gar_tot;
return estimate();
}
And the HTML:
<div id="main-bg" class="main-img">
<img src="images/house.jpg" width="100%">
</div>
<div id="main-ppa" class="main-img">
<img src="images/house-paved-patio.png" width="100%">
</div>
<div id="main-gar" class="main-img">
<img src="images/house-garage.png" width="100%">
</div>
<div id="main-cpo" class="main-img">
<img src="images/house-covered-porch.png" width="100%">
</div>
<div id="main-cpa" class="main-img">
<img src="images/house-covered-patio.png" width="100%">
</div>
<div id="estimate"></div>
<script>
document.getElementById("estimate").innerHTML = "Your estimated total is $" + calculate_total('main-ppa', 'main-cpa', 'main-cpo', 'main-gar');
</script>
With the CSS something like:
#main-ppa {display:none;}
#main-gar {display:block;}
#main-cpo {display:block;}
#main-cpa {display:none;}
Any help would be greatly appreciated.