IE not loading script?

T

Tony

I have a select with an onchange - it works find in Firefox, but in IE
6 I get an error: Object Expected.

I have simplified things drastically, and still get the error.

The HTML:

<select name="viewtrain" id="viewtrain" onchange="viewDetails(this);">
<option value="1">Train 1</option>
<option value="2">Train 2</option>
<option value="3">Train 3</option>
</select>

and the javascript:

function viewDetails(sel)
{
alert('hi');
}

For some reason, this fails. But if I replace viewDetails with an
alert:
<select name="viewtrain" id="viewtrain" onchange="alert(this);">
everything works correctly.

For some reason, it seems that IE isn't 'seeing' viewDetails.

-
OK I did a bit more checking before posting, and it seems that the js
file isn't loading at all - but only in IE. I can't imagine why.
here's the source:

<script type="text/javascript" src="js/CalendarPopup.js"></script>
<script type="text/javascript" src="js/details.js"></script>
<script type="text/javascript">
ACTIVE_SECTION = 'Late Trains Details';
</script>

The stuff before and after works fine. Only details.js is not loading
- and only in IE.

I'm stumped on this one...
 
A

Andrew Bailey

stumps me too.


I have a select with an onchange - it works find in Firefox, but in IE
6 I get an error: Object Expected.

I have simplified things drastically, and still get the error.

The HTML:

<select name="viewtrain" id="viewtrain" onchange="viewDetails(this);">
<option value="1">Train 1</option>
<option value="2">Train 2</option>
<option value="3">Train 3</option>
</select>

and the javascript:

function viewDetails(sel)
{
alert('hi');

}

For some reason, this fails. But if I replace viewDetails with an
alert:
<select name="viewtrain" id="viewtrain" onchange="alert(this);">
everything works correctly.

For some reason, it seems that IE isn't 'seeing' viewDetails.

-
OK I did a bit more checking before posting, and it seems that the js
file isn't loading at all - but only in IE. I can't imagine why.
here's the source:

<script type="text/javascript" src="js/CalendarPopup.js"></script>
<script type="text/javascript" src="js/details.js"></script>
<script type="text/javascript">
ACTIVE_SECTION = 'Late Trains Details';
</script>

The stuff before and after works fine. Only details.js is not loading
- and only in IE.

I'm stumped on this one...

Is it because you're calling details.js but the actual file is called
Details.js with a capital?

Andy
 
T

Tony

stumps me too.













Is it because you're calling details.js but the actual file is called
Details.js with a capital?

Andy

That wasn't the problem - I had rechecked the path & capitalization.

Finally figured it out. There was a variable named 'class' in the
file. Apparently, IE doesn't like that. Changing it to 'classname'
fixed the problem.
 
T

Thomas 'PointedEars' Lahn

Tony said:
[...]
<script type="text/javascript" src="js/CalendarPopup.js"></script>
<script type="text/javascript" src="js/details.js"></script>
<script type="text/javascript">
ACTIVE_SECTION = 'Late Trains Details';
</script>
The stuff before and after works fine. Only details.js is not loading
- and only in IE.
I'm stumped on this one...
Is it because you're calling details.js but the actual file is called
Details.js with a capital?
[...]

That wasn't the problem - I had rechecked the path & capitalization.

Finally figured it out. There was a variable named 'class' in the
file. Apparently, IE doesn't like that. Changing it to 'classname'
fixed the problem.

No ECMAScript-compliant engine likes it if you use reserved words for
identifiers.


PointedEars
 
B

Bart Van der Donck

Tony said:
That wasn't the problem - I had rechecked the path & capitalization.

Finally figured it out. There was a variable named 'class' in the
file. Apparently, IE doesn't like that. Changing it to 'classname'
fixed the problem.

Then you are lucky this time. But 'classname' is also reserved; best
to rename it again.
 
E

Evertjan.

Bart Van der Donck wrote on 24 apr 2008 in comp.lang.javascript:
Then you are lucky this time. But 'classname' is also reserved; best
to rename it again.

'className' is, not 'classname'.
 
B

Bart Van der Donck

Evertjan. said:
Bart Van der Donck wrote on 24 apr 2008 in comp.lang.javascript:

Not my oracle!

Mine neither :) I doubt if 'className' would have been supported
anyhow in those browsers.
 
T

Thomas 'PointedEars' Lahn

Bart said:
Then you are lucky this time. But 'classname' is also reserved;

No, it is not, and neither is `className'.
best to rename it again.

That depends on where that identifier is used. As a *variable name* like
here, it is completely harmless.


PointedEars
 
B

Bart Van der Donck

Thomas said:
Bart said:
But 'classname' is also reserved [...]

No, it is not, and neither is `className'.

I was not referring to the official "Reserved Words"; I used the word
'reserved' outside of that context.
That depends on where that identifier is used.  

Correct, but as you undoubtedly know better than me, a variable name
is only a property of the window-object. You will want to avoid
confusion and not use things like window.className. A good deal of
programmers will interpret such code as an attempt to influence the
class of the window (if such a thing would exist). Of course your
statement is theoretically true; but it leads to bad habits and
dangerous consequences in practice. Software is not an exact science.
As a *variable name* like here, it is completely harmless.

Is it "completely harmless" to create confusion like that ? No, it
isn't. Better keep things clear when writing code; rule number one as
far as I'm concerned.
 
E

Evertjan.

Bart Van der Donck wrote on 27 apr 2008 in comp.lang.javascript:
Thomas said:
Bart said:
But 'classname' is also reserved [...]

No, it is not, and neither is `className'.

I was not referring to the official "Reserved Words"; I used the word
'reserved' outside of that context.
That depends on where that identifier is used.  

Correct, but as you undoubtedly know better than me, a variable name
is only a property of the window-object. You will want to avoid
confusion and not use things like window.className. A good deal of
programmers will interpret such code as an attempt to influence the
class of the window (if such a thing would exist). Of course your
statement is theoretically true; but it leads to bad habits and
dangerous consequences in practice. Software is not an exact science.
As a *variable name* like here, it is completely harmless.

Is it "completely harmless" to create confusion like that ? No, it
isn't.

Indeed it isn't.
Test these before and afther the mouseovers,
It will confuse anyone but Thomas:

<style type='text/css'>
..x {background-color:blue;}
</style>

<span
id='d1'
classname='z'
onmouseover='this.className="x"'>
Hi
</span>

<button onclick='alert(document.getElementById("d1").classname)'>
click</button>
<p>
<span
id='d2'
className='z'
onmouseover='this.className="x"'>
Hi
</span>

<button onclick='alert(document.getElementById("d2").className)'>
click</button>
 
T

Thomas 'PointedEars' Lahn

Bart said:
Thomas said:
Bart said:
But 'classname' is also reserved [...]
No, it is not, and neither is `className'.

I was not referring to the official "Reserved Words"; I used the word
'reserved' outside of that context.

I just wanted to make things clear to the dedicated reader.
Correct, but as you undoubtedly know better than me, a variable name
is only a property of the window-object.

Yes, I do, for your statement is imprecise at best. Variables become
properties of the *Variable Object of the execution context* they have been
declared in, with the DontDelete attribute. That object is the Global
Object only for the global execution context. The Global Object only MAY
have a host-defined property named `window' that refers to the Global Object
again, and even that reference target cannot be taken for granted.
You will want to avoid confusion and not use things like window.className.
A good deal of programmers will interpret such code as an attempt
to influence the class of the window (if such a thing would exist).
^^^^^^^^^^^^^^^^^^^^^^^^^^^
There, don't you see? I don't have time to care about clueless programmers
(JFTR, that does not mean "newbies" which is quite different). A Window
object is not an HTML DOM object and therefore is unlikely to have a
*host-defined property* named `className'. I would avoid adding a property
to a host object, but I don't see a problem of using `classname' or
`className' as a variable name, provided the semantics of the identifier fit
the context in which it is used.
Of course your statement is theoretically true; but it leads to bad habits and
dangerous consequences in practice. Software is not an exact science.

To acquire the result of misconceptions about code as a bad habit is the
choice of its reader of that code to make, and not my task to prevent or
avoid. For I would consider it a requirement for survival in this
informational age to be a able to weigh perceived information carefully
before it is being accepted as the truth and become applied knowledge later.
Is it "completely harmless" to create confusion like that ? No, it
isn't. Better keep things clear when writing code; rule number one as
far as I'm concerned.

Any piece of source code can cause all kinds of confusion among the
uninitiated. If I were to consider that every time I write a line of code,
I would never ever finish any program because people are so very different,
and so numerous are the different ways in which they can err.


PointedEars
 
A

abcdefghij444

Thomas said:
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
There, don't you see?  I don't have time to care about clueless programmers
(JFTR, that does not mean "newbies" which is quite different).

What's that, a clueless programmer ? Someone who doesn't know that
'className' is not a host-defined property of the window-object ? Such
a thing could happen to me too. You can't expect from a programmer to
know all host objects and their properties by head.

Nothing wrong with not knowing something, as long as you know the
places where to look it up.

It *IS* the duty of the programmer to write clear code as to avoid
(possible) ambiguity wherever he can. Do your code readers, your
successor and yourself-in-the-future a favour :)

I'm almost sure you will change your view sooner or later.
 
T

Tony

Tony said:
[...]
<script type="text/javascript" src="js/CalendarPopup.js"></script>
<script type="text/javascript" src="js/details.js"></script>
<script type="text/javascript">
ACTIVE_SECTION = 'Late Trains Details';
</script>
The stuff before and after works fine. Only details.js is not loading
- and only in IE.
I'm stumped on this one...
Is it because you're calling details.js but the actual file is called
Details.js with a capital?
[...]
That wasn't the problem - I had rechecked the path & capitalization.
Finally figured it out. There was a variable named 'class' in the
file. Apparently, IE doesn't like that. Changing it to 'classname'
fixed the problem.

No ECMAScript-compliant engine likes it if you use reserved words for
identifiers.

PointedEars

Interesting that IE had a problem with 'class', but FireFox didn't.
Does it follow that FireFox is not ECMAScript-compliant?
 
T

Thomas 'PointedEars' Lahn

Tony said:
Interesting that IE had a problem with 'class', but FireFox didn't.
Does it follow that FireFox is not ECMAScript-compliant?

No, Firefox (i.e. JavaScript 1.5+) issues only a warning:

| (!) class is a reserved identifier
|
| var class = "foo";


PointedEars
 

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,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top