Reputation: 15
For some reason my code will not work and I need help with outputing the sum of three numbers entered by the user in textboxes
function sum() {
var text1 = parseInt(document.getElementById('text1').value),
text2 = parseInt(document.getElementById('text2').value),
text3 = parseInt(document.getElementById('text3').value);
var result = text1 + text2 + text3;
if(!isNaN(result)) {
document.getElementById(output).innerHTML = result;
}
Here is the HTML code where I want the result shown - straight after 'Magic Number Is:'
<div class="output">
<b>Magic number is:<span id="output"></span><br />
Thank you in advance
Upvotes: 0
Views: 51
Reputation: 1195
You forgot the quotes.
document.getElementById("output").innerHTML = result.
Upvotes: 1
Reputation: 512
getElementById
is not well written ;)
document.getElementById("output").innerHTML = result;
Upvotes: 0