/    Sign up×
Community /Pin to ProfileBookmark

Trying to get to fields to add together

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 (&pound</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 (&pound</label>
<div class=”input-container”>
<input type=”sum” input name=”amount” value=”” id=”result” placeholder=”Amount to pay…”>
</div>
</div>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@rootJan 28.2018 — Please don't make duplicate posts. The reason is it stops confusion and you get your response faster.
×

Success!

Help @MazUK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...