Lee Hamilton
Lee Hamilton

Reputation: 60

JavaScript is not printing my HTML

I have this function:

function suggestSell() {
    var sellValue = document.getElementById('sellValue');
    var btcVol = document.getElementById('btcVol');
    var grossSell = btcVol * sellValue ;
    var sellFee = grossSell * .006;
    var sellOff = grossSell - sellFee;
    document.write('<p>sellValue: ' + sellValue.innerHTML +
                   '<br> btcVol: ' + btcVol.innerHTML +
                   '<br> grossSell: ' + grossSell +
                   '<br> sellFee: ' + sellFee +
                   '<br> sellOff: ' + sellOff +
                   '<br></p>');  
}

that i call like this:

<script>suggestSell();</script>

But it displays this in the browser.

1156.161.42053359undefinedundefinedundefined

Upvotes: 0

Views: 73

Answers (1)

karthikr
karthikr

Reputation: 99620

var sellValue = document.getElementById('sellValue');

selects the node. You probably need the value

var sellValue = document.getElementById('sellValue').value;

Same thing for btcVol

var btcVol = document.getElementById('btcVol').value;

If you do make this change, note that sellValue.innerHTML and btcVol.innerHTML should be changed appropriately.

Upvotes: 2

Related Questions