www.webdeveloper.com
Results 1 to 2 of 2

Thread: Keep getting NaN on a simple form-based calculator...

  1. #1
    Join Date
    Nov 2010
    Posts
    1

    Keep getting NaN on a simple form-based calculator...

    I keep getting a NaN on this form-based calculator I am trying to make... I can't figure out what I am doing wrong. Any input, or in this case "output", would be greatly appreciated. Here is the code:

    Code:
    <script type="text/javascript">
    
    function calculateBudget()
    {
    var totalBudget = document.getElementById('TotalBudget');
    var listCost = document.getElementById('ListCost');
    var postage = document.getElementById('Postage');
    var printing = document.getElementById('Printing');
    var uses = document.getElementById('Uses');
    
    var totalRecords = document.getElementById('TotalRecords');
    
    totalBudget = parseFloat(totalBudget);
    listCost = parseFloat(listCost);
    postage = parseFloat(postage);
    printing = parseFloat(printing);
    uses = parseFloat(uses);
    
    var result1 = postage + printing;
    var result2 = result1 * uses + listCost;
    var result3 = listCost / result2;
    var result4 = totalBudget * result3;
    
    totalRecords.value = 0;
    totalRecords.value = parseFloat(totalRecords.value);
    totalRecords.value = parseFloat(totalRecords.value) + result4 / listCost;
    }
    </script>

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,354

    Try this ...

    Note you are getting the element using the ID, but you are not getting the value.
    Try ...
    Code:
    function calculateBudget()
    {
    var totalBudget = document.getElementById('TotalBudget').value;
    var listCost = document.getElementById('ListCost').value;
    var postage = document.getElementById('Postage').value;
    var printing = document.getElementById('Printing').value;
    var uses = document.getElementById('Uses').value;
    ...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles