...

View Full Version : Why is my function null/undefined?



GreenhornPup
06-19-2012, 02:37 AM
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":

<input type="button" value="Submit" onclick="processProperties()">


And here is my processProperties() function below:


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
06-19-2012, 03:07 AM
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
06-19-2012, 06:48 AM
OK, here goes...


<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>

felgall
06-19-2012, 10:42 AM
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:



<body onload="page_onload()">



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


<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.

GreenhornPup
06-19-2012, 03:21 PM
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! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum