Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Why is my function null/undefined?

    My Internet Explorer F12 thingy keeps pointing at the following line and saying that "the value of the property 'processProperties' is null or undefined, not a Function object":
    Code:
    <input type="button" value="Submit" onclick="processProperties()">
    And here is my processProperties() function below:

    Code:
    function processProperties()
    {
      var marketTextbox = document.taxForm.txtMarket;
      var resultsTextbox = document.taxForm.results;
      var i;
    
      for(i=1; i<=numOfEntries; i++)
      {
    
        if(isNaN(marketTextbox.value) == true)
        {
          alert("Numbers only, please");
        }
        else if (marketTextbox.value < 0)
        {
          alert("Positive numbers only, please");
        }
        else 
        {
          marketValues[marketValues.length] = parseFloat(marketTextbox.value);
          resultsTextbox.value = computeTax(marketTextbox.value);
        }
       
      }  // end for
      printSummary();
      
    }  // end fn

  • #2
    New Coder
    Join Date
    Jun 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It is in the <head> of my page. Would it help if I posted the whole page to shed a little more light on this problem?

  • #3
    New Coder
    Join Date
    Jun 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    OK, here goes...

    Code:
    <html>
    <head>
    <title>The Evil Tax Collector</title>
    <script language="JavaScript">
    
    var numOfEntries;
    var limit = 20;
    var marketValues = new Array();
    var taxes = new Array();
    
    
    function page_onload()
    {
      numOfEntries = prompt("Please enter how many market values you have as long as you have 20 or less", "");
      if (isNaN(numOfEntries) == true) 
      {
        numOfEntries = prompt("Numbers only please", "");
      }
      else if ((numOfEntries < 0) || (numOfEntries > 20))
      {
        prompt("Your number must be between 0 and 20");
      }
      numOfEntries = parseInt(numOfEntries);
    
    
    function computeTax(market)
    {
      var taxDetails = "";
      var assessedValue = market * 0.28;
      taxes[taxes.length] = assessedValue * 0.125;
      taxDetails = "The tax on the property with a market value of $" + market + " is $" + taxes[taxes.length];
      return taxDetails;
    }
    
    
    function printSummary()
    {
      var i;
      var totalTax;
    
      for(i=0; i<taxes.length; i++)
      {
        totalTax += taxes[i];
      }
      document.taxForm.results.value = "The total taxes add up to $" + totalTax;
    }
    
    
    function processProperties()
    {
      var marketTextbox = document.taxForm.txtMarket;
      var resultsTextbox = document.taxForm.results;
      var i;
    
      for(i=1; i<=numOfEntries; i++)
      {
    
        if(isNaN(marketTextbox.value) == true)
        {
          alert("Numbers only, please");
        }
        else if (marketTextbox.value < 0)
        {
          alert("Positive numbers only, please");
        }
        else 
        {
          marketValues[marketValues.length] = parseFloat(marketTextbox.value);
          resultsTextbox.value = computeTax(marketTextbox.value);
        }
       
      }  // end for
      printSummary();
      
    }  // end fn
    
    
    </script>
    </head>
    <body language="JavaScript" onload="page_onload()">
    <h1>The Evil Tax Collector</h1>
    <h2>Here to collect your soul!</h2>
    Please enter a market value and click Submit.<br><br>
    <form name="taxForm">
    Market Value: <input type="text" name="txtMarket"><br><br>
    <input type="button" value="Submit" onclick="processProperties()">
    <input type="reset" value="Nevermind"><br><br>
    <textarea cols=50 rows=20 name="results"></textarea>
    </form>
    </body>
    </html>

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,479
    Thanks
    0
    Thanked 635 Times in 625 Posts
    The body tag should always just be written <body> unless you need to attach an id to identify the page for the CSS so even the following is antiquated:

    Quote Originally Posted by iBall View Post
    Code:
    <body onload="page_onload()">


    onload is a JavaScript event handler and so belongs inside script tags:

    Code:
    <body>
    ...
    
    ...
    <script type="text/javascript">
    window.onload = page_onload;
    </script>
    </body>
    Of course the rest of the JavaScript also goes with the onload - and once you are sure the script works you should move the entire script to its own separate file and simply reference it from all the pages you want to call it from.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    GreenhornPup (06-19-2012)

  • #5
    New Coder
    Join Date
    Jun 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you all for your helpful advice! I admit, the JavaScript book I'm using is pretty old, so I guess this is confirmation that I need to order myself a new one from Amazon. I just thought I would save a few dollars by using my old one, but now I see how much the language has changed since it was published.

    So in the meantime, Stephen, I will certainly be checking out your JavaScript help site. Thank you for posting the link!


  •  

    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
    •