doublelift2
doublelift2

Reputation: 15

Output a result of numbers

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

Answers (2)

user1721803
user1721803

Reputation: 1195

You forgot the quotes.

document.getElementById("output").innerHTML = result.

Upvotes: 1

Hotted24
Hotted24

Reputation: 512

getElementById is not well written ;)

document.getElementById("output").innerHTML = result;

Upvotes: 0

Related Questions