S
Sean McCourt
Hi I am doing a JavaScript course and learning from the recommed book
(JavaScript 3rd Edition by Don Gosslin)
Below is one of the exercises from the book. I get this error message
when I try to use the calculator.
"document.Calculate.Input is null or not an object"
Can someone please tell me why this is?
I have checked and double checked that my code is exactly the same as
the book.
Thanks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Calculator exercise P120</title>
<META NAME="Generator" CONTENT="Stone's WebWriter 3.5">
<meta http-equiv="content-type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
<!-- hide from incompatible browsers
/*
the function is used to update the inputString variable above
x += y is the same as x = x + y
the variable named inputString contains the operands and operators of
the calculation
after the calculation is added to the input string variable, the
calculation is performed using the eval() function
the function updateString() accepts a single value representing a
number or operator
the value is then added to the inputString variable using the +=
assignment operator
after the inputString variable is updated, it is assigned the value of
a text box in the form
go to validator.w3.org/file-upload.html to validate this document
*/
var inputString = "";
function updateString(value)
{
inputString += value;
document.Calculator.Input.value = inputString;
}
// Stop hiding from incompatible browsers -->
</script>
</head>
<body>
<form name="Calculator" action =""> <!-- adds a form element -->
<input type="text name="Input" /><br /><br /> <!-- adds an input text
box -->
<!-- // each element along with the other elements sends a value to
the updateString() function using an onclick method -->
<input type="button" name="plus" value=" + " onclick="updateString(' +
')" />
<input type="button" name="minus" value=" - " onclick="updateString('
- ')" />
<input type="button" name="times" value=" x " onclick="updateString('
* ')" />
<input type="button" name="div" value=" / " onclick="updateString(' /
')" />
<input type="button" name="mod" value=" mod " onclick="updateString('
% ')" /><br />
<input type="button" name="zero" value=" 0 " onclick="updateString(' 0
')" />
<input type="button" name="one" value=" 1 " onclick="updateString(' 1
')" />
<input type="button" name="two" value=" 2 " onclick="updateString(' 2
')" />
<input type="button" name="three" value=" 3 " onclick="updateString('
3 ')" />
<input type="button" name="four" value=" 4 " onclick="updateString(' 4
')" /><br />
<input type="button" name="five" value=" 5 " onclick="updateString(' 5
')" />
<input type="button" name="six" value=" 6 " onclick="updateString(' 6
')" />
<input type="button" name="seven" value=" 7 " onclick="updateString('
7 ')" />
<input type="button" name="eight" value=" 8 " onclick="updateString('
8 ')" />
<input type="button" name="nine" value=" 9 " onclick="updateString(' 9
')" />
<br />
<!-- // the onclick event for the calc button performs the calculation
using the eval() function with the input string variable -->
<!-- // the calculated value is then assigned as the value of the
input text box -->
<input type="button" name="point" value=" . " onclick="updateString('
.. ')" />
<input type="button" name="clear" value=" clear "
onclick="document.Calculator.Input.value=''; inputString=''" />
<input type="button" name="calc" value=" = "
onclick="document.Calculator.Input.value=eval(inputString);
inputString=''" />
</form>
</body>
</html>
(JavaScript 3rd Edition by Don Gosslin)
Below is one of the exercises from the book. I get this error message
when I try to use the calculator.
"document.Calculate.Input is null or not an object"
Can someone please tell me why this is?
I have checked and double checked that my code is exactly the same as
the book.
Thanks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Calculator exercise P120</title>
<META NAME="Generator" CONTENT="Stone's WebWriter 3.5">
<meta http-equiv="content-type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
<!-- hide from incompatible browsers
/*
the function is used to update the inputString variable above
x += y is the same as x = x + y
the variable named inputString contains the operands and operators of
the calculation
after the calculation is added to the input string variable, the
calculation is performed using the eval() function
the function updateString() accepts a single value representing a
number or operator
the value is then added to the inputString variable using the +=
assignment operator
after the inputString variable is updated, it is assigned the value of
a text box in the form
go to validator.w3.org/file-upload.html to validate this document
*/
var inputString = "";
function updateString(value)
{
inputString += value;
document.Calculator.Input.value = inputString;
}
// Stop hiding from incompatible browsers -->
</script>
</head>
<body>
<form name="Calculator" action =""> <!-- adds a form element -->
<input type="text name="Input" /><br /><br /> <!-- adds an input text
box -->
<!-- // each element along with the other elements sends a value to
the updateString() function using an onclick method -->
<input type="button" name="plus" value=" + " onclick="updateString(' +
')" />
<input type="button" name="minus" value=" - " onclick="updateString('
- ')" />
<input type="button" name="times" value=" x " onclick="updateString('
* ')" />
<input type="button" name="div" value=" / " onclick="updateString(' /
')" />
<input type="button" name="mod" value=" mod " onclick="updateString('
% ')" /><br />
<input type="button" name="zero" value=" 0 " onclick="updateString(' 0
')" />
<input type="button" name="one" value=" 1 " onclick="updateString(' 1
')" />
<input type="button" name="two" value=" 2 " onclick="updateString(' 2
')" />
<input type="button" name="three" value=" 3 " onclick="updateString('
3 ')" />
<input type="button" name="four" value=" 4 " onclick="updateString(' 4
')" /><br />
<input type="button" name="five" value=" 5 " onclick="updateString(' 5
')" />
<input type="button" name="six" value=" 6 " onclick="updateString(' 6
')" />
<input type="button" name="seven" value=" 7 " onclick="updateString('
7 ')" />
<input type="button" name="eight" value=" 8 " onclick="updateString('
8 ')" />
<input type="button" name="nine" value=" 9 " onclick="updateString(' 9
')" />
<br />
<!-- // the onclick event for the calc button performs the calculation
using the eval() function with the input string variable -->
<!-- // the calculated value is then assigned as the value of the
input text box -->
<input type="button" name="point" value=" . " onclick="updateString('
.. ')" />
<input type="button" name="clear" value=" clear "
onclick="document.Calculator.Input.value=''; inputString=''" />
<input type="button" name="calc" value=" = "
onclick="document.Calculator.Input.value=eval(inputString);
inputString=''" />
</form>
</body>
</html>