473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Client-side JavaScript weirdness with assigning a form element -in Windows / IE6 only. Any ideas?

I have this snippet of client side code running:

var makeField = document.forms[0][makeFieldName];

alert("makeFieldName name,length,type=" + makeFieldName + ", " +
makeField.name + "," + makeField.length + "," + makeField.type);
The alert is just in there for debugging.

The function containing this code is called when a select field option is
changed. makeFieldName is the name of the select field in the form.

It works correctly from:

OS X / Safari
OS X / IE
OS X / Firefox
Windows / Firefox

but doesn't work right in Windows / IE6.

The diagnostic alert that shows up from all the browsers except Windows /
IE6 is the same:

makeFieldName name,length,type=1_onlyCarMake, 1_onlyCarMake,63,select-one

In other words, the makeFieldName is correct (1_onlyCarMake), and is the
same as makeField.name. The correct field is found and it has the right
number of options and the correct type for a select field.

But in Windows / IE6 only the diagnostic alert shows up with:

makeFieldName name,length,type=1_onlyCarMake, startWith,undefined,hidden

The startWith field happens to be the first field in that form (the only
form in the document, by the way) and it is, in fact, a hidden field. Thus
it makes sense that the length shown is undefined, since it is not a select
field and thus has no options array.

The problem is - why is Windows /IE6 incorrectly returning that field as a
result of the expression "document.forms[0][makeFieldName]" when all the
other browsers are returning the correct field?

It doesn't make any different whether I use document.forms[0][makeFieldName]
or actually specify the name of the form, as in
document["thisFormName"][makeFieldName]. In either case it works everywhere
but in Windows / IE6.

Anybody have any idea why the client is confused and returning the first
form element rather than the named one?

Thanks!

doug
Jan 21 '06 #1
8 1659
I fixed it! It's definitely a weird Windows-only IE-only bug.

Another staff member had taken part of my code and transplanted it. When she
did this she created a couple of rather strange-looking identifiers that I
never would have made, like "1_onlyCarMake, starting with an integer.

Those are illegal JavaScript identifiers if they are used in the
dot.notation syntax. But they *should* be perfectly legal if used in the
associative array syntax (in quotes, in square brackets), which we were
doing.

It was fine in all the browsers except Windows / IE6 choked on them.

When I changed the identifiers to something that didn't start with an
integer, like onlyCar1Make, it all worked in all browsers.

Just something to be aware of when coding for Windows / IE!

doug
On 1/21/06 12:41 PM, in article BF*****************@lerner.net, "Doug
Lerner" <do**@lerner.net> wrote:
I have this snippet of client side code running:

var makeField = document.forms[0][makeFieldName];

alert("makeFieldName name,length,type=" + makeFieldName + ", " +
makeField.name + "," + makeField.length + "," + makeField.type);
The alert is just in there for debugging.

The function containing this code is called when a select field option is
changed. makeFieldName is the name of the select field in the form.

It works correctly from:

OS X / Safari
OS X / IE
OS X / Firefox
Windows / Firefox

but doesn't work right in Windows / IE6.

The diagnostic alert that shows up from all the browsers except Windows /
IE6 is the same:

makeFieldName name,length,type=1_onlyCarMake, 1_onlyCarMake,63,select-one

In other words, the makeFieldName is correct (1_onlyCarMake), and is the
same as makeField.name. The correct field is found and it has the right
number of options and the correct type for a select field.

But in Windows / IE6 only the diagnostic alert shows up with:

makeFieldName name,length,type=1_onlyCarMake, startWith,undefined,hidden

The startWith field happens to be the first field in that form (the only
form in the document, by the way) and it is, in fact, a hidden field. Thus
it makes sense that the length shown is undefined, since it is not a select
field and thus has no options array.

The problem is - why is Windows /IE6 incorrectly returning that field as a
result of the expression "document.forms[0][makeFieldName]" when all the
other browsers are returning the correct field?

It doesn't make any different whether I use document.forms[0][makeFieldName]
or actually specify the name of the form, as in
document["thisFormName"][makeFieldName]. In either case it works everywhere
but in Windows / IE6.

Anybody have any idea why the client is confused and returning the first
form element rather than the named one?

Thanks!

doug


Jan 21 '06 #2
On 2006-01-21, Doug Lerner <do**@lerner.net> wrote:

makeFieldName name,length,type=1_onlyCarMake, startWith,undefined,hidden

Anybody have any idea why the client is confused and returning the first
form element rather than the named one?


possibly the digit at the start of the name is confusing it.

Bye.
Jasen
Jan 21 '06 #3
Be careful relying on this implementation. What you are running into in IE6
is not a bug, rather you may consider it compliance with standards.
Browsers are becoming more and more standards compliant. When the
aforementioned browsers conform to Item 7.6 in the ECMAScript Language
Specification your code will no longer work in those browsers.

An identifier is described as:

IdentifierStart::
UnicodeLetter
$
_
\ UnicodeEscapeSequence

A NumberLiteral does not conform to this standard. The reason for this is
demonstrated more clearly in section 7.8.3 while defining HexIntegerLiteral.
It states:

"The source character immediately following a NumberLiteral must not be an
IdentifierStart or DecimalDigit."

The browsers in which your code works are ignoring the IdentifierStart
definition and holding to wording in 7.8.3 to imply that any characters
directly following a NumberLiteral must be part of an Identifier because an
IdentifierStart may not immediately follow a NumberLiteral. The biggest
drawback to this interpretation is going to be in the debugging arena. The
debugging will not be as accurate or as informative. More than likely this
will be realized by the browser authors and the code in question will no
longer be valid. If you continue to code in this manner may I suggest that
you declare all your variables with the 'var' statement. This will not keep
your code from breaking should the standard be adopted. However it will
make your debugging experience much more efficient and enjoyable.

~Digital~
"Doug Lerner" <do**@lerner.net> wrote in message
news:BFF801EB.1C994%do**@lerner.net...
I fixed it! It's definitely a weird Windows-only IE-only bug.

Another staff member had taken part of my code and transplanted it. When
she
did this she created a couple of rather strange-looking identifiers that I
never would have made, like "1_onlyCarMake, starting with an integer.

Those are illegal JavaScript identifiers if they are used in the
dot.notation syntax. But they *should* be perfectly legal if used in the
associative array syntax (in quotes, in square brackets), which we were
doing.

It was fine in all the browsers except Windows / IE6 choked on them.

When I changed the identifiers to something that didn't start with an
integer, like onlyCar1Make, it all worked in all browsers.

Just something to be aware of when coding for Windows / IE!

doug
On 1/21/06 12:41 PM, in article BFF7DC8E.1C878%do**@lerner.net, "Doug
Lerner" <do**@lerner.net> wrote:
I have this snippet of client side code running:

var makeField = document.forms[0][makeFieldName];

alert("makeFieldName name,length,type=" + makeFieldName + ", " +
makeField.name + "," + makeField.length + "," + makeField.type);
The alert is just in there for debugging.

The function containing this code is called when a select field option is
changed. makeFieldName is the name of the select field in the form.

It works correctly from:

OS X / Safari
OS X / IE
OS X / Firefox
Windows / Firefox

but doesn't work right in Windows / IE6.

The diagnostic alert that shows up from all the browsers except Windows /
IE6 is the same:

makeFieldName name,length,type=1_onlyCarMake, 1_onlyCarMake,63,select-one

In other words, the makeFieldName is correct (1_onlyCarMake), and is the
same as makeField.name. The correct field is found and it has the right
number of options and the correct type for a select field.

But in Windows / IE6 only the diagnostic alert shows up with:

makeFieldName name,length,type=1_onlyCarMake, startWith,undefined,hidden

The startWith field happens to be the first field in that form (the only
form in the document, by the way) and it is, in fact, a hidden field.
Thus
it makes sense that the length shown is undefined, since it is not a
select
field and thus has no options array.

The problem is - why is Windows /IE6 incorrectly returning that field as
a
result of the expression "document.forms[0][makeFieldName]" when all the
other browsers are returning the correct field?

It doesn't make any different whether I use
document.forms[0][makeFieldName]
or actually specify the name of the form, as in
document["thisFormName"][makeFieldName]. In either case it works
everywhere
but in Windows / IE6.

Anybody have any idea why the client is confused and returning the first
form element rather than the named one?

Thanks!

doug

Jan 21 '06 #4
Digital wrote:
Be careful relying on this implementation.
It has often been observed that individuals who top-post to Usenet show
evidence of not actually reading the messages that they are responding
to. In this case I suspect that the (minimal) discipline of creating a
well-formed Usenet post, with responses following trimmed quotes of
preceding messages that provide the context for the response, would have
avoided your posting an essentially irrelevant response.
What you are running into in IE6 is not a bug, rather you
may consider it compliance with standards. Browsers are
becoming more and more standards compliant. When the
aforementioned browsers conform to Item 7.6 in the ECMAScript
Language Specification your code will no longer work in
those browsers. <snip>

However:-
Doug Lerner wrote:

<snip>
Those are illegal JavaScript identifiers if they are used in
the dot.notation syntax. But they *should* be perfectly legal
if used in the associative array syntax (in quotes, in square
brackets), which we were doing.

<snip>

- so the applicable section of ECMA 262 is section 11.2.1, where the
production rules and algorithms for the bracket notation property
accessor make it clear that ECMAScript places no restrictions upon the
sequences of characters that may be used as the property names of
object, and accessed with bracket notation.

The correspondence of a property name with an Identifier is only
significant for dot notation property accessors.

Richard.
Jan 21 '06 #5
"Richard Cornford" <Ri*****@litotes.demon.co.uk> writes:
- so the applicable section of ECMA 262 is section 11.2.1, where the
production rules and algorithms for the bracket notation property
accessor make it clear that ECMAScript places no restrictions upon the
sequences of characters that may be used as the property names of
object, and accessed with bracket notation.


Very true. While I thought I had understood this, it was still
something of an experience when I realised that the empty string
was a valid property name :)

var x = {};
x[""] = 42;
alert(x[""]);

Well, I think it's cute. :)
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jan 21 '06 #6
Richard -

Section 11.2.1 makes one explicit statement about Identifiers and
identifier-strings:

"where <indentifier-string> is a string literal containing the same sequence
of characters as the Identifier."

Section 11.2.1 is the only section in the specificiation that makes mention
of identifier-strings. Therefore Section 11.2.1 should be taken literally
to mean that the indentifier-string in bracket notation should contain the
same sequence of characters as if the identifier-string were to be used as
an Identifier as there are no other ECMA 262 rules that can take precedence.
To mazimize the life of code written one should comply.

Again, this is most important when it comes to creating and using debuggers
as object-model trees currently depend on dot-notation. By using an
identifier-string that represents an illegal identifier you are forced to
hand-type each element you wish to watch instead of being able to navigate
via point and click. This becomes even more cumbersome when using a
debugger like Venkmann that does not allow inline editing of watch
statements but rather forces the developer to always add a new statement.

~Digital~

"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:dq*******************@news.demon.co.uk...
Digital wrote:
Be careful relying on this implementation.


It has often been observed that individuals who top-post to Usenet show
evidence of not actually reading the messages that they are responding
to. In this case I suspect that the (minimal) discipline of creating a
well-formed Usenet post, with responses following trimmed quotes of
preceding messages that provide the context for the response, would have
avoided your posting an essentially irrelevant response.
What you are running into in IE6 is not a bug, rather you
may consider it compliance with standards. Browsers are
becoming more and more standards compliant. When the
aforementioned browsers conform to Item 7.6 in the ECMAScript
Language Specification your code will no longer work in
those browsers.

<snip>

However:-
Doug Lerner wrote:

<snip>
Those are illegal JavaScript identifiers if they are used in
the dot.notation syntax. But they *should* be perfectly legal
if used in the associative array syntax (in quotes, in square
brackets), which we were doing.

<snip>

- so the applicable section of ECMA 262 is section 11.2.1, where the
production rules and algorithms for the bracket notation property
accessor make it clear that ECMAScript places no restrictions upon the
sequences of characters that may be used as the property names of
object, and accessed with bracket notation.

The correspondence of a property name with an Identifier is only
significant for dot notation property accessors.

Richard.

Jan 21 '06 #7
I did mention in my note that I changed the identifier.

But isn't what you are saying only true with respect to actual identifiers?

If you are using the associative array syntax it shouldn't matter because
properties are really only associative array elements.

So while

a.1_something

is definitely not legal,

a["1_something"]

is perfectly legal.

What is inside brackets does not have to be a "legal indentifier". In fact,
that is one purpose of having that notation (the other being able to have
dynamically named properties).

That's why I think it is a bug for IE6 not to recognize that.

doug

On 1/22/06 4:05 AM, in article JB******************@tornado.rdc-kc.rr.com,
"Digital" <re****@spam.com> wrote:
Be careful relying on this implementation. What you are running into in IE6
is not a bug, rather you may consider it compliance with standards.
Browsers are becoming more and more standards compliant. When the
aforementioned browsers conform to Item 7.6 in the ECMAScript Language
Specification your code will no longer work in those browsers.

An identifier is described as:

IdentifierStart::
UnicodeLetter
$
_
\ UnicodeEscapeSequence

A NumberLiteral does not conform to this standard. The reason for this is
demonstrated more clearly in section 7.8.3 while defining HexIntegerLiteral.
It states:

"The source character immediately following a NumberLiteral must not be an
IdentifierStart or DecimalDigit."

The browsers in which your code works are ignoring the IdentifierStart
definition and holding to wording in 7.8.3 to imply that any characters
directly following a NumberLiteral must be part of an Identifier because an
IdentifierStart may not immediately follow a NumberLiteral. The biggest
drawback to this interpretation is going to be in the debugging arena. The
debugging will not be as accurate or as informative. More than likely this
will be realized by the browser authors and the code in question will no
longer be valid. If you continue to code in this manner may I suggest that
you declare all your variables with the 'var' statement. This will not keep
your code from breaking should the standard be adopted. However it will
make your debugging experience much more efficient and enjoyable.

~Digital~
"Doug Lerner" <do**@lerner.net> wrote in message
news:BFF801EB.1C994%do**@lerner.net...
I fixed it! It's definitely a weird Windows-only IE-only bug.

Another staff member had taken part of my code and transplanted it. When
she
did this she created a couple of rather strange-looking identifiers that I
never would have made, like "1_onlyCarMake, starting with an integer.

Those are illegal JavaScript identifiers if they are used in the
dot.notation syntax. But they *should* be perfectly legal if used in the
associative array syntax (in quotes, in square brackets), which we were
doing.

It was fine in all the browsers except Windows / IE6 choked on them.

When I changed the identifiers to something that didn't start with an
integer, like onlyCar1Make, it all worked in all browsers.

Just something to be aware of when coding for Windows / IE!

doug
On 1/21/06 12:41 PM, in article BFF7DC8E.1C878%do**@lerner.net, "Doug
Lerner" <do**@lerner.net> wrote:
I have this snippet of client side code running:

var makeField = document.forms[0][makeFieldName];

alert("makeFieldName name,length,type=" + makeFieldName + ", " +
makeField.name + "," + makeField.length + "," + makeField.type);
The alert is just in there for debugging.

The function containing this code is called when a select field option is
changed. makeFieldName is the name of the select field in the form.

It works correctly from:

OS X / Safari
OS X / IE
OS X / Firefox
Windows / Firefox

but doesn't work right in Windows / IE6.

The diagnostic alert that shows up from all the browsers except Windows /
IE6 is the same:

makeFieldName name,length,type=1_onlyCarMake, 1_onlyCarMake,63,select-one

In other words, the makeFieldName is correct (1_onlyCarMake), and is the
same as makeField.name. The correct field is found and it has the right
number of options and the correct type for a select field.

But in Windows / IE6 only the diagnostic alert shows up with:

makeFieldName name,length,type=1_onlyCarMake, startWith,undefined,hidden

The startWith field happens to be the first field in that form (the only
form in the document, by the way) and it is, in fact, a hidden field.
Thus
it makes sense that the length shown is undefined, since it is not a
select
field and thus has no options array.

The problem is - why is Windows /IE6 incorrectly returning that field as
a
result of the expression "document.forms[0][makeFieldName]" when all the
other browsers are returning the correct field?

It doesn't make any different whether I use
document.forms[0][makeFieldName]
or actually specify the name of the form, as in
document["thisFormName"][makeFieldName]. In either case it works
everywhere
but in Windows / IE6.

Anybody have any idea why the client is confused and returning the first
form element rather than the named one?

Thanks!

doug



Jan 22 '06 #8
Digital wrote:
<snip>
Section 11.2.1 makes one explicit statement about Identifiers
and identifier-strings:

"where <indentifier-string> is a string literal containing
the same sequence of characters as the Identifier."
You are reading too much into what is actually an explanatory text. That
section is explaining that when a bracket notation property accessor
uses exactly the same character sequence as the property name as a dot
notation property accessor their behaviour is identical. In order to
express the equivalence in behaviour it is necessary for the bracket
notation property accessor to use a property name that is an Identifier
because that restriction applies to dot notation.

This allows the specification to define actual behaviour of property
accessors with a single algorithm and leave the production rules for dot
notation to imply the additional restriction upon the token following
the dot.

The specified productions for bracket notation property accessors are:-

MemberExpression [ Expression ]
CallExpression [ Expression ]

- and '<identifier-string>' is not a defined component of the language
at all (it does not appear in appendix A).
Section 11.2.1 is the only section in the specificiation that
makes mention of identifier-strings.
And only in an explanation of behaviour.
Therefore Section 11.2.1 should be taken literally to mean
that the indentifier-string in bracket notation should
contain the same sequence of characters as if the
identifier-string were to be used as an Identifier as there
are no other ECMA 262 rules that can take precedence.
The algorithm actually takes precedence:-

<quote cite="ECMA 262, 3rd ed. section 11.2.1">
The production MemberExpression : MemberExpression [ Expression ] is
evaluated as follows:

1. Evaluate MemberExpression.
2. Call GetValue(Result(1)).
3. Evaluate Expression.
4. Call GetValue(Result(3)).
5. Call ToObject(Result(2)).
6. Call ToString(Result(4)).
7. Return a value of type Reference whose base object is Result(5)
and whose property name is Result(6).

The production CallExpression : CallExpression [ Expression ] is
evaluated in exactly the same manner, except that the contained
CallExpression is evaluated in step 1.
</quote>

Where we find no examination of the nature of the string that will stand
as the object's property name. If any restriction were intended it would
have to be applied in that algorithm, and after the evaluation of the
Expression within the brackets.
To mazimize the life of code written one should comply.
No such restriction applies so complying with it is unnecessary. It is
also practically impossible to comply because the 'array index' members
of an array can only be accessed by bracket notation property accessors
(the specification contains no alternative mechanism), and an 'array
index' cannot qualify as an Identifier.
Again, this is most important when it comes to creating and
using debuggers ... <snip>

As the '<Identifier string>' premise is false this debugger
consideration is likely a red herring.
Richard Cornford" <Richard...

<snip>

Please do not top-post to comp.lang.javascript. Even if you do not care
for the long established Usenet conventions your example has potential
to do harm to others.

Richard.
Jan 22 '06 #9

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

Similar topics

2
by: news.microsoft.com | last post by:
Hi I write dll library which one of it component will be Net socket communication. Communication is working very good, but i've got problem when client is connecting. When server is started,...
2
by: Delmar | last post by:
I need to build Web Application that will generate a client to execute some operations. Each client has running silent application. Maybe somebody can advice me what can I do ? Thank you.
13
by: Sandeep Singh | last post by:
I am making socket client application in C# how can i get ip address of client who has connected to server
14
by: Ankit Aneja | last post by:
The code of classes given below is for server to which clients connect i want to get ip address of client which has connected pls help how can i get //listen class public class listen {
2
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless...
2
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
0
by: khu84 | last post by:
Here is client server very simple code, seems to work with telnet but with with web client code gives blank output. Following is the server code:- <?php function...
0
by: 85ssp | last post by:
I am creating a small server client program that is meant for up to 70 connections from 70 different computers on a network. Everything in the program functions correctly except when testing...
4
MMcCarthy
by: MMcCarthy | last post by:
http://bytes.com/images/howtos/projectscope_blocks.jpgAs a freelance IT consultant for over 10 years, I’ve come to appreciate well defined project scopes. A project scope is a common understanding...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.