473,548 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

learning JavaScript - Need help with an exercise

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.Calcu late.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>Calculat or 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.or g/file-upload.html to validate this document

*/

var inputString = "";
function updateString(va lue)
{
inputString += value;
document.Calcul ator.Input.valu e = inputString;
}

// Stop hiding from incompatible browsers -->
</script>
</head>

<body>

<form name="Calculato r" 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="update String(' +
')" />
<input type="button" name="minus" value=" - " onclick="update String('
- ')" />
<input type="button" name="times" value=" x " onclick="update String('
* ')" />
<input type="button" name="div" value=" / " onclick="update String(' /
')" />
<input type="button" name="mod" value=" mod " onclick="update String('
% ')" /><br />
<input type="button" name="zero" value=" 0 " onclick="update String(' 0
')" />
<input type="button" name="one" value=" 1 " onclick="update String(' 1
')" />
<input type="button" name="two" value=" 2 " onclick="update String(' 2
')" />
<input type="button" name="three" value=" 3 " onclick="update String('
3 ')" />
<input type="button" name="four" value=" 4 " onclick="update String(' 4
')" /><br />
<input type="button" name="five" value=" 5 " onclick="update String(' 5
')" />
<input type="button" name="six" value=" 6 " onclick="update String(' 6
')" />
<input type="button" name="seven" value=" 7 " onclick="update String('
7 ')" />
<input type="button" name="eight" value=" 8 " onclick="update String('
8 ')" />
<input type="button" name="nine" value=" 9 " onclick="update String(' 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="update String('
.. ')" />
<input type="button" name="clear" value=" clear "
onclick="docume nt.Calculator.I nput.value=''; inputString=''" />
<input type="button" name="calc" value=" = "
onclick="docume nt.Calculator.I nput.value=eval (inputString);
inputString=''" />

</form>

</body>

</html>
Jul 23 '05 #1
3 2552
Sean McCourt wrote:
Hi I am doing a JavaScript course and learning from the recommed book
(JavaScript 3rd Edition by Don Gosslin)
If the code you have posted is representative of what the book teaches
you, you need a new book.
Below is one of the exercises from the book. I get this error message
when I try to use the calculator.

"document.Calcu late.Input is null or not an object"

Can someone please tell me why this is?
Yes.
I have checked and double checked that my code is exactly the same as
the book.
You missed the one thing killing it, that validating the HTML would have
caught.
<--snip-->

go to validator.w3.or g/file-upload.html to validate this document
From your own code, had you done that it would have pointed out the
problem.

<--snip-->
<input type="text name="Input" /><br /><br /> <!-- adds an input text


type="text" note the closing " after the word text that you are missing.

<--snip-->

That is ignoring the <!-- //--> that are *not* needed in modern
browsers. It also ignores the eval usage, although it could be argued
that the use given is an "adequate" use of eval, there are better
methods to creating a JS driven calculator.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #2
Sean McCourt wrote:
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.Calcu late.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


I note Randy has replied with a solution, however since we're in the
same boat (but I'm a little ahead of you learning javascript) I find
the Mozilla web browser handy for helping me solve problems as it has a
Javascript console that gives you better error messages... thus, I
suggest you go to http://www.mozilla.org and near the lower right
corner, you'll see a link for Mozilla 1.7.5... Download it and use it as
your browser... If you want to see any errors in your codeing, select
Tools, Web Development, Javascript Console from the menu and it'll save
you posting here and waiting for replies...

Best of luck... you'll reach a few bumps along the way but don't be put
off - javascript is rather useful for your skillset...

randelld
Jul 23 '05 #3
Thank you both for your help

On Mon, 14 Mar 2005 14:15:25 +1100, Sean McCourt <sm*@ihug.com.a u>
wrote:
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.Calc ulate.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>Calcula tor 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.or g/file-upload.html to validate this document

*/

var inputString = "";
function updateString(va lue)
{
inputString += value;
document.Calcul ator.Input.valu e = inputString;
}

// Stop hiding from incompatible browsers -->
</script>
</head>

<body>

<form name="Calculato r" 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="update String(' +
')" />
<input type="button" name="minus" value=" - " onclick="update String('
- ')" />
<input type="button" name="times" value=" x " onclick="update String('
* ')" />
<input type="button" name="div" value=" / " onclick="update String(' /
')" />
<input type="button" name="mod" value=" mod " onclick="update String('
% ')" /><br />
<input type="button" name="zero" value=" 0 " onclick="update String(' 0
')" />
<input type="button" name="one" value=" 1 " onclick="update String(' 1
')" />
<input type="button" name="two" value=" 2 " onclick="update String(' 2
')" />
<input type="button" name="three" value=" 3 " onclick="update String('
3 ')" />
<input type="button" name="four" value=" 4 " onclick="update String(' 4
')" /><br />
<input type="button" name="five" value=" 5 " onclick="update String(' 5
')" />
<input type="button" name="six" value=" 6 " onclick="update String(' 6
')" />
<input type="button" name="seven" value=" 7 " onclick="update String('
7 ')" />
<input type="button" name="eight" value=" 8 " onclick="update String('
8 ')" />
<input type="button" name="nine" value=" 9 " onclick="update String(' 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="update String('
. ')" />
<input type="button" name="clear" value=" clear "
onclick="docum ent.Calculator. Input.value=''; inputString=''" />
<input type="button" name="calc" value=" = "
onclick="docum ent.Calculator. Input.value=eva l(inputString);
inputString='' " />

</form>

</body>

</html>


Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1965
by: Trvl Orm | last post by:
I am working with 2 frames, Left and Right and the main code is in the left frame, which has been attached. Can someone please help me with this code. I am new to JavaScript and can't figure it out. What needs to happen is this: On the left frame you should have a series of buttons, which when pushed makes things happen on the right...
9
4504
by: CW | last post by:
I wrote an HTML based chat application. The front end is built entirely on HTML + javascript. Essentially, I have a hidden frame that's refreshed frequently and any new messages are displayed in another frame using document.write. My problem is that since chat screen can be obscured by other applications/windows, I have no way of informing...
1
9599
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the...
1
1282
by: Brent Ritchie | last post by:
Hello, I put up a small web application called SVG Creator, I'm developing it as a learning exercise. The url is: http://www3.sympatico.ca/brentritchie/. So far development is going well, but; I am having problems getting cross browser compatability. I use IE, Opera and Firefox as testing environments, but as soon as I added in dynamic...
2
308
by: rich | last post by:
I'd like to improve my webdesign knowledge and learn how to write Javascripts. I have built my own website. I have javascripts on my site that I havent written. I download them and edit them where I need to to fit my site and then put them in. I have dabbed alittle bit into computer programming some years ago. Trying to teach myself and...
4
1441
by: DjShifta | last post by:
Ok this really shouldn't be that hard...but I can not figure out whats' wrong for the life of me. I am brand new to "coding" and have thus far just built basic sites with Dreamweaver, but am going through my CIW certs, and this is an exercise i am feeling a little "dumb'' on.... any help.... Question exactly as it's worded: Create a Web page...
60
4948
by: marss | last post by:
Maybe anyone know good free online JavaScript knowledge test? This not exactly a system for testing online required - it may be simply list of questions with variants of answers (I have to prepare tests for learners and I need something to be taken as basis). I was able to find only this (http://www.w3schools.com/js/ js_quiz.asp), but I...
4
1933
by: somenath | last post by:
Hi All, I have some questions about the process of learning C language. I see in this groups all expert most of the time quote from C standard. 1) My question is do all of you study the C standard as the part of your learning C language? 2) Is it very much required to study line by line of the C standard to
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7803
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.