Hi
Would appreciate some advice as an amateur!
I’m trying to get the code below to add up 2 rows/fields to give the total in the last field <input type=”sum” input name=”amount” value=”” id=”result” placeholder=”Amount to pay…”> but it doesn’t add the 2 together!
<div class=”form-row”>
<label>Property or Property Ref:</label>
<div class=”input-container”>
<input type=”text” name=”property” placeholder=”Please tell us which property this payment relates to…”>
</div>
</div>
<script type=”text/javascript”>
function calc(A,B,SUM) {
var one = Number(A);
if (isNaN(one)) { alert(‘Invalid entry: ‘+A); one=0; }
var two = Number(document.getElementById(?.value);
if (isNaN(two)) { alert(‘Invalid entry: ‘+?; two=0; }
document.getElementById(SUM).value = one + two;
}
</script>
<div class=”form-row”>
<label>Amount to Pay (£</label>
<div class=”input-container”>
<input type=”text” name=”sum1″ placeholder=”Amount to pay…”>
<id=”op1″ value=”” onChange=”calc(this.value,’op2′,’result’)” />
</div>
</div>
<div class=”form-row”>
<label>Non-internet/bank transfer handling fee:</label>
<div class=”input-container”>
<input name=”sum2″ value=”5.00″ id=”op2″ onChange=”calc(this.value,’op1′,’result’)” />
<div class=”form-row”>
<label>Total to Pay (£</label>
<div class=”input-container”>
<input type=”sum” input name=”amount” value=”” id=”result” placeholder=”Amount to pay…”>
</div>
</div>