OK, I’ll post the code in it’s entirely (html/touch of CSS/& JS) so you can see where I’m getting things from…
It’s a calculator for shipping purposes, and 95% of it is functional. If you select “CM,” any and all calculations there are correct. If you select “IN,” the calculations are correct, however it does NOT compare the value of “volumelbs” to that of “actualweight” to determine which is larger.
That is the issue I’m running into. (hope this makes sense…new to code forums, so my wording may not be on par)
Here’s the code (let me know if I should edit it out and add a fiddle or js.do instead).
<script src=
"https://code.jquery.com/jquery-1.12.4.min.js">
</script>
<style type="text/css">
.selectt {
display: none;
}
#et-boc > div > div > div > div > div > div.et_pb_module.et_pb_code.et_pb_code_1 > div > div.Inches.selectt { display: block; }
</style>
<div style="text-align:center;">
<div style="width:49%; float:left;">
<label>
<input type="radio" name="colorRadio"
value="Inches" checked> Inches</label>
</div>
<div style="width:49%; float:left;">
<label>
<input type="radio" name="colorRadio"
value="Centimeters"> Centimeters</label>
</div>
</div>
<br>
<div style="width:45%;float:left; margin-right:10%;">
<p>Length</p>
<p>Width</p>
<p>Height</p>
<br>
<p>Actual Weight</p>
<p>Volumetric Weight</p>
<br>
<p>Total Cost*</p>
</div>
<div class="Centimeters selectt" style="width:45%; float:left; text-align:right;">
<div>
<p><input type="Text" id="length" name="length" size="4" onkeyup=""> cm</p>
<p><input type="Text" name="width" id="width" size="4"> cm</p>
<p><input type="Text" id="height" name="height" size="4" onkeyup=""> cm</p>
<br>
<p><input type="Text" name="actualWeight" id="actualWeight" size="4"> kg<span style="opacity:0"> </span> </p>
<p><input type="Text" name="volume" id="volume" size="4" readonly="readonly" style="border:none;"><span style="opacity:0">s</span> <span style="opacity:0">s</span> kg<span style="opacity:0"> </span> </p>
<br>
<p>$<input type="Text" name="totalcost" id="totalcost" size="4" readonly="readonly" style="border:none;"> </p>
</div>
<br>
<p><input type="button" name="calculate" id="volume" size="4" onclick="calculateTotal()" value="Calculate"></p>
</div>
<div class="Inches selectt" style="width:45%; float:left; text-align:right;">
<div>
<p><input type="Text" id="lengthlbs" name="lengthlbs" size="4" onkeyup=""> in<span style="opacity:0">s</span> </p>
<p><input type="Text" name="widthlbs" id="widthlbs" size="4"> in<span style="opacity:0">s</span> </p>
<p><input type="Text" id="heightlbs" name="heightlbs" size="4" onkeyup=""> in<span style="opacity:0">s</span> </p>
<br>
<p><input type="Text" name="actualWeight" id="actualWeight" size="4"> lbs</p>
<p><input name="volumelbs" id="volumelbs" size="4" readonly="readonly" style="border:none;"><span style="opacity:0">s</span> <span style="opacity:0">s</span> lbs</p>
<br>
<p>$<input type="Text" name="totalcost2" id="totalcost2" size="4" readonly="readonly" style="border:none;"> </p>
</div>
<br>
<p><input type="button" name="calculate" id="volumelbs" size="4" onclick="calculateTotal()" value="Calculate"></p>
</div>
<script>
$(document).ready(function() {
$('input[type="radio"]').click(function() {
var inputValue = $(this).attr("value");
var targetBox = $("." + inputValue);
$(".selectt").not(targetBox).hide();
$(targetBox).show();
});
});
function calculateTotal (){
var width = +document.getElementById("width").value;
var height =+document.getElementById("height").value;
var length =+document.getElementById("length").value;
var actualWeight =+document.getElementById("actualWeight").value;
var actualWeight = actualWeight.toFixed(1);
var actualWeight = Math.ceil(actualWeight*2)/2;
var volume = (width * height * length) / 5000;
var volume = volume.toFixed(1);
var volume = Math.ceil(volume*2)/2;
document.getElementById("volume").value = volume;
let billedWeight = Math.max(volume, actualWeight);
var widthlbs = +document.getElementById("widthlbs").value;
var heightlbs =+document.getElementById("heightlbs").value;
var lengthlbs =+document.getElementById("lengthlbs").value;
var volumelbs = (widthlbs * heightlbs * lengthlbs) / 138.4;
var volumelbs = volumelbs.toFixed(1);
var volumelbs = Math.ceil(volumelbs*2)/2;
document.getElementById("volumelbs").value = volumelbs;
let billedWeight2 = Math.max(volumelbs, actualWeight);
if (volume > 0){
var totalcost = ((billedWeight*2.2046226218)/2)*5;
var totalcost = totalcost.toFixed(2);
document.getElementById("totalcost").value = totalcost;
}
if (volumelbs > 0) {
var totalcost2 = (billedWeight2*2)*5;
document.getElementById("totalcost2").value = totalcost2;
}
}
</script>