By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,514 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Bizarre JS bug involving brackets (IE6/SP2)

P: n/a
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/...i1/bk8_1i2.htm (works)
http://www.exeter.ac.uk/cimt/mepres/...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


Jul 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a


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 http://www.exeter.ac.uk/cimt/mepres/...1i2_faulty.htm
(faulty)


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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

P: n/a

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:41**********************@newsread4.arcor-online.net...

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
Jul 23 '05 #3

P: n/a
On Wed, 29 Sep 2004 16:23:09 +0100, Al Reynolds <aj******@bat400.com>
wrote:

[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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4

P: n/a
On Wed, 29 Sep 2004 23:04:19 GMT, Michael Winter
<M.******@blueyonder.co.invalid> wrote:

[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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5

P: n/a
"Al Reynolds" <aj******@bat400.com> wrote in message news:<cj**********@south.jnrs.ja.net>...
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
Jul 23 '05 #6

P: n/a
"Robert" <rc*******@my-deja.com> wrote in message
news:c6**************************@posting.google.c om...
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
Jul 23 '05 #7

P: n/a

"Al Reynolds" <aj******@bat400.com> wrote in message
news:cj**********@south.jnrs.ja.net...
"Robert" <rc*******@my-deja.com> wrote in message
news:c6**************************@posting.google.c om...
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


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

Jul 23 '05 #8

P: n/a
"Michael Winter" <M.******@blueyonder.co.invalid> wrote:
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
Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.