Bizarre JS bug involving brackets (IE6/SP2)

A

Al Reynolds

Afternoon,

I have just finished fixing one of my scripts after it started
generating odd errors on IE6 on WinXP Service Pack 2.

For info, the IE Version is:
6.0.2900.2180.xpsp_sp2_rtm.040803-2158
I have done all the Windows critical updates. I haven't
managed to replicate the behaviour in any other browser.
I have tested the faulty version in Netscape 4.7x, IE 5
and Opera 7 and it works fine in all three.

The two files are here:
http://www.exeter.ac.uk/cimt/mepres/book8/bk8i1/bk8_1i2.htm (works)
http://www.exeter.ac.uk/cimt/mepres/book8/bk8i1/bk8_1i2_faulty.htm
(faulty)

There is only *one* difference between the two files in line 29.

To make it work, I had to change:
inputbox.value = numq+ag-cw-cc;
to:
inputbox.value = numq+(ag)-(cw)-(cc);

In the faulty version, the page generates two errors while
downloading:
(i) Line 33 Char 16 Expected ')'
(ii) Line 1076 Char 19 Expected ';'

Line 33 is "pc = ((cc*100)+extra)/numq;"
Line 1076 is "tands = 'Y8 Unit '+unit+' Section '+section;"

In these lines, chars 16 and 19 are both "+" signs.

Now I cannot work out for the life of me what the problem is!
Anyone have any ideas?

Al
 
M

Martin Honnen

Al Reynolds wrote:

I have just finished fixing one of my scripts after it started
generating odd errors on IE6 on WinXP Service Pack 2.

For info, the IE Version is:
6.0.2900.2180.xpsp_sp2_rtm.040803-2158

One thing is for sure, JavaScript comments are not done with
<!-- comment -->
as you seem to think and make use of in the script section on that page
but rather need to be written as
// comment
for a one line comment or as
/* comment
comment
*/
if you need several lines.
Try taking those
<!-- comment -->
lines out and you are improving your chances that browsers do not report
syntax errors.
 
A

Al Reynolds

Martin Honnen said:
One thing is for sure, JavaScript comments are not done with
<!-- comment -->
as you seem to think and make use of in the script section on that page
but rather need to be written as
// comment
for a one line comment or as
/* comment
comment
*/
if you need several lines.
Try taking those
<!-- comment -->
lines out and you are improving your chances that browsers do not report
syntax errors.

So you don't know the answer to the question then? I've already
solved the problem - the details were in my original post - so the
format I used for my comments wasn't part of the problem. I'll
be sure to use the correct commenting technique in the future.

Al
 
M

Michael Winter

[snip]
Now I cannot work out for the life of me what the problem is!
Anyone have any ideas?

It would be nice to know how to replicate the problem. Using the system
correctly doesn't produce errors, and it's too late for me to experiment,
so what does?

A couple of quick comments:

1) Validate your pages.
2) Why are all but one of your variables global? That's asking for trouble.
3) Mind explaining the purpose of those eval calls in the Calculate
function?

Mike
 
M

Michael Winter

On Wed, 29 Sep 2004 23:04:19 GMT, Michael Winter

[snip]
A couple of quick comments:

Forgot an important one: making a feedback form dependent upon Javascript
is a *very* bad idea. Using a pop-up is even worse. Contact forms
shouldn't require anything from the user agent other than the ability to
parse HTML. They can use more, by all means, but they shouldn't require
more.

[snip]

Mike
 
R

Robert

Al Reynolds said:
I've already
solved the problem - the details were in my original post - so the
format I used for my comments wasn't part of the problem.


The last lines of the original post read in my newsreader:


"Now I cannot work out for the life of me what the problem is!
Anyone have any ideas?"


Seems like you were looking for any reason the script might be in
error and it doesn't read like all the problems were solve at the
time.


Hard to believe there is a difference in these lines:

To make it work, I had to change:
inputbox.value = numq+ag-cw-cc;
to:
inputbox.value = numq+(ag)-(cw)-(cc);


I'd assume the real problem code was somewhere else and this change
just happened to avoid the problem.

Robert
 
A

Al Reynolds

Robert said:
Hard to believe there is a difference in these lines:

To make it work, I had to change:
inputbox.value = numq+ag-cw-cc;
to:
inputbox.value = numq+(ag)-(cw)-(cc);


I'd assume the real problem code was somewhere else and this change
just happened to avoid the problem.

The two files are *identical* apart from this line.

Al
 
A

Al Reynolds

Al Reynolds said:
The two files are *identical* apart from this line.

Al

I should have added: so you're probably right. But I can't
work out why. There are no references to any of these
variables anywhere else other than where they should be.

Al
 
A

Al Reynolds

Michael Winter said:
It would be nice to know how to replicate the problem.

If I get time, I will take out other code until the error ceases
appearing. I'll let you know what I find.
A couple of quick comments:
1) Validate your pages.

One of the problems with writing code that will work in NS4.7x
without excessive use of multiple code for different browsers is
that it doesn't do well on most validation tests. But it's a fair point.
2) Why are all but one of your variables global? That's asking for
trouble.

Indeed. As someone who learnt to program in the strongly-typed
structured environment demanded by Modula-2, almost everything
involved in Javascript seems like "asking for trouble" to me. As a
result I use naming conventions to try and avoid side-effects.
3) Mind explaining the purpose of those eval calls in the Calculate
function?

Probably a remnant of some NS4.7x compatible code that didn't
have a constant inside the brackets. These things happen when code
is developed in an "organic" way.
Forgot an important one: making a feedback form dependent upon Javascript
is a *very* bad idea. Using a pop-up is even worse. Contact forms
shouldn't require anything from the user agent other than the ability to
parse HTML. They can use more, by all means, but they shouldn't require
more.

Another fair point. Since the entire page requires javascript to
operate, I have used it for the feedback mechanism. The few
people who can't use the page because of not having Javascript
turned on (but can't work out why) could use the email link to
request some assistance.

Please don't ask me why I'm writing code that still work in NS4.7x.

Al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top