I am trying to make an area calculator and I cannot figure out what am I missing.
the area field is not updating when entering numbers in each field.
Any advice please? I wonder if I’m missing something very important.
Many thanks in advance
Here is my html:
<tr>
<th style="text-align: left;"><label>Slab Width (m): </label></th>
<th><div class="input-box">
<input type="text" name="slab_width" onkeypress="return isNumber(event)" onkeyup="calculateArea()" required="" class="form-control">
</div></th>
</tr>
<tr>
<th style="text-align: left;"><label>Slab Length (m): </label></th>
<th><div class="input-box">
<input type="text" name="slab_length" onkeypress="return isNumber(event)" onkeyup="calculateArea()" required="" class="form-control">
</div></th>
</tr>
<tr>
<th style="text-align: left;"><label>Total Area (m2):</label></th>
<th><div class="input-box">
<input type="text" name="slabsArea" disabled="" class="form-control">
</div></th>
</tr>
</table>```
And here is the script for it:
function calculateArea() {
var form = document.getElementById("calc");
var sLength = parseFloat(form.elements["slab_length"].value);
var sHeight = parseFloat(form.elements["slab_width"].value);
var slabsArea = slabWidth * slabLength;
//slabsArea = Math.round(slabsArea);
//document.getElementById("slabsArea").value = slabsArea;
form.elements["slabsArea"].value = slabsArea;
return slabsArea;
}