itstudent101
itstudent101

Reputation: 43

Beginner JavaScript- Results not posting in result box

Hey all i've just begun javascript programming and I can't figure out why my program isn't "doing the math". When I input numbers into the boxes it wont give me results in the result boxes at the bottom. I'm not sure if I need to separate the script into multiple calculations or leave it the way it is. This is my first project with javascript and I am not sure if I missed something or not. Any help will be very appreciated.

<!DOCTYPE html>
<html>
<head>
    <title>Javascript Financial Formulas</title>

    <script type="text/javascript">
    function calculateLoan(){
    
    var Profit = parseFloat(document.getElementID("Profit").value);
    var AverageNumberOfShares = parseInt(document.getElementById("AverageNumberOfShares").value);    
    var PricePerShare = parseFloat(document.getElementById("PricePerShare").value);
    var TotalAssets = parseFloat(document.getElementID("TotalAssets").value);
    var IntangibleAssets = parseFloat(document.getElementID("IntangibleAssets").value);
    var Liabilities = parseFloat(document.getElementID("Liabilities").value);
    var PricePerShare = parseFloat(document.getElementID("PricePerShare").value);
    var EarningsPerShare = parseFloat(document.getElementID("EarningsPerShare").value);
    var PERatio = parseFloat(document.getElementID("PERatio").value);
    var PercentExpectedGrowth = parseFloat(document.getElementID("PercentExpectedGrowth").value);
    
    
    var EarningsPerShare;
    var PriceToBook;
    var PERatio;
    var PriceToEarningsGrowth;


    EarningsPerShare = Profit / AverageNumberOfShares;
    PriceToBook = PricePerShare / (TotalAssets - (IntangibleAssets + Liabilities));
    PERatio = PricePerShare / EarningsPerShare;
    PriceToEarningsGrowth = PERatio / PercentExpectedGrowth;


    document.getElementById("EarningsPerShare").value = EarningsPerShare;
    document.getElementById("PriceToBook").value = PriceToBook;
    document.getElementById("PERatio").value = PERatio;
    document.getElementById("PriceToEarningsGrowth").value = PriceToEarningsGrowth;

    }
    </script>

</head>
<body>
    <h1>Javascript Financial Formulas</h1>
    <p>To use, please input financial information and press calculate<p>
        <form name="Financial Formulas">
        <p>Earnings per share:<p>
        Profit:
        <input type = "text" id="Profit" name="Profit" value="" /><br />
        Average number of shares:
        <input type = "text" id="AverageNumberOfShares" name="AverageNumberOfShares" value="" /><br />
        
        <p>Price to Book:<p>
        Price per share:
        <input type = "text" id="PricePerShare" name="PricePerShare" value="" /><br />
        Total Assets:
        <input type = "text" id="TotalAssets" name="TotalAssets" value="" /><br />
        Intangible Assets:
        <input type = "text" id="IntangibleAssets" name="IntangibleAssets" value="" /><br />
        Liabilities:
        <input type = "text" id="Liabilities" name="Liabilities" value="" /><br />

        <p>PE Ratio:<p>
        Price per share:
        <input type = "text" id="PricePerShare" name="PricePerShare" value="" /><br />
        Earnings per share:
        <input type = "text" id="EarningsPerShare" name="EarningsPerShare" value="" /><br />

        <p>Price to Earnings Growth:<p>
        PE Ratio:
        <input type = "text" id="PERatio" name="PERatio" value="" /><br />
        Percent Expected Growth:
        <input type = "text" id="PercentExpectedGrowth" name="PercentExpectedGrowth" value="" /><br />


        <input type = "button" id="calculate" name="Calculate" value="Calculate" onclick="calculateLoan();" /> 

        <input type = "reset" id="Reset" name="Reset" value="Reset" /><br />


            <br>
        Earnings per share:
        <input type = "text" id="EarningsPerShare" name="EarningsPerShare:" value="" /><br />
        Price to Book:
        <input type = "text" id="PriceToBook" name="PriceToBook:" value="" /><br />
        PE Ratio:
        <input type = "text" id="PERatio" name="PERatio:" value="" /><br />
        Price to Earnings Growth:
        <input type = "text" id="PriceToEarningsGrowth" name="PriceToEarningsGrowth:" value="" /><br />

        </form>

    </body>
    </html>

Upvotes: 0

Views: 26

Answers (1)

ylerjen
ylerjen

Reputation: 4259

If it's your first javascript program, you'll be happy to know there is a console output in browsers. Just press F12 and you'll see the error printed. :)

In your case, the error is about getElementById that you have wrongly spelled getElementId.

Error says :

Uncaught TypeError: document.getElementID is not a function

Upvotes: 1

Related Questions