So I've been working on a small beginner javascript project that takes employee data and calculates and prints to the total with a functioning clear button. For whatever reason, I can't get the calculate function to run.
Here's my calc function and my form:
function calcPay(payHr, regHr, otHr) {
var basePay = (payHr.value * regHr.value);
var otPay = (otHr.value * (payHr.value * 1.5));
var total = (basePay + otPay);
total.value = total + total;
}
<form name="Payroll">
<p>Employee1 ID:
<input type="text" id="eid1" name="eid1">Pay per hour:
<input type="text" id="pph1" name="pph1">Hours worked:
<input type="text" id=" rhw1" name="rhw1">Overtime worked:
<input type="text" id="otw1" name="otw1"></p>
<p>Employee2 ID:
<input type="text" id="eid2" name="eid2">Pay per hour:
<input type="text" id="pph2" name="pph2">Hours worked:
<input type="text" id="rhw2" name="rhw2">Overtime worked:
<input type="text" id="otw2" name="otw2"></p>
<p>Employee3 ID:
<input type="text" id="eid3" name="eid3">Pay per hour:
<input type="text" id="pph3" name="pph3">Hours worked:
<input type="text" id="rhw3" name="rhw3">Overtime worked:
<input type="text" id="otw3" name="otw3"></p>
<input type="button" name="toClick" onclick="JavaScript: calcPay(pph1, rhw1, otw1);calcPay(pph2, rhw2, otw2); calcPay(pph3, rhw3, otw3);" value="Calculate">
<input type="button" name="toClick" onclick="JavaScript: clearField();" value="Clear All">
<br>
<br>
<p>Total payout this week:
<input type="text" id="total" value="total">
</form>
Thanks! :D