Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-19-2012, 01:37 AM   PM User | #1
GreenhornPup
New Coder

 
Join Date: Jun 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GreenhornPup is an unknown quantity at this point
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
GreenhornPup is offline   Reply With Quote
Old 06-19-2012, 02:07 AM   PM User | #2
GreenhornPup
New Coder

 
Join Date: Jun 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GreenhornPup is an unknown quantity at this point
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?
GreenhornPup is offline   Reply With Quote
Old 06-19-2012, 05:48 AM   PM User | #3
GreenhornPup
New Coder

 
Join Date: Jun 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GreenhornPup is an unknown quantity at this point
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>
GreenhornPup is offline   Reply With Quote
Old 06-19-2012, 09:42 AM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,462
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
GreenhornPup (06-19-2012)
Old 06-19-2012, 02:21 PM   PM User | #5
GreenhornPup
New Coder

 
Join Date: Jun 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GreenhornPup is an unknown quantity at this point
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!
GreenhornPup is offline   Reply With Quote
Reply

Bookmarks

Tags
button, functions, null, onclick, undefined

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:13 AM.


Advertisement
Log in to turn off these ads.