From: FAQ server on
-----------------------------------------------------------------------
FAQ Topic - My element is named myselect[], how do I access
it?
-----------------------------------------------------------------------

Form controls with any "illegal" characters can be accessed with
` formref.elements["myselect[]"] ` - The bracket characters,
amongst others, are illegal in ID attributes and javascript
identifiers, so you should try to avoid them as browsers may
handle them incorrectly.

http://msdn.microsoft.com/en-us/library/ms537449%28VS.85%29.aspx

http://docs.sun.com/source/816-6408-10/form.htm

http://jibbering.com/faq/notes/square-brackets/


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.

From: Richard Cornford on
On Apr 9, 5:38 am, Garrett Smith wrote:
<snip>
>>http://jibbering.com/faq/notes/square-brackets/
>
> That faq note provides the example:
>
>| var stringOfValue = document.formName.inpName.value;

Which is preceded by the statement; "Various forms of dot notation
property accessor can be used to reference the "value" property of the
input element. One of the simplest is:-", which is factual in that
various forms can be used (name a single HTML DOM implementation where
the 'shortcut' accessors will not work with the mark-up shown) and the
example is one of the simplest that can be used. The point of the
example is to show equivalence between bracket notation property
accessors, for which any additional complexity and elaboration would
be unhelpful.

> That is nonstandard

Except in the sense that it has never been possible to show an HTML
DOM environment where they don't work. But being standard or not is
not relevant to which (recognizable) forms of bracket notation
accessors would be equivalent (to showing the relationship between the
strings in the brackets and the Identifiers following the dots).

Proposing this change is as silly as the previous suggestion that
pointing out the equivalence between - document.body -,
document['body'] - and - doucment['bo'+'dy'] - was wrong because
nobody would ever use the latter two. Understanding how things work is
not dependent on how they would be used.

> and can result in a leaked form control. HTML 5
> terms this as some sort of feature.
>
> How about:
> | var stringOfValue = document.forms.formName.elements.inpName.value;

The next line of text reads; "This dot notation has three dots, so
there are three points at which the square bracket notation could be
used in place of the dot notation (these are all equivalent)". You
want to have five dots, and so must add the additional equivalents to
the following text, making it considerably more complex without adding
anything to the explanation that is being provided (indeed, probably
making it less clear).

> ?
>
> Although standard form control access is not the point of the
> article,

And examples of actual form access (rather than examples only of dot/
bracket-notation property accessors) use the standard form access
methods.

> the examples should not propose the reader to use non-standard
> access.

It doesn't. Indeed pointing out that the simple 'shortcut' form exists
and then not using it in the form access examples could be seen as
discouraging its use (as the observant reader may recognize that not
using the 'shortcut' accessors to work with forms would have been a
deliberate decision).

> Considering this is linked from an entry on how to access a named
> form control, it has the effect of advocating non-standard code.

There is a perfectly good article in the notes talking about form
access that states the relative status of the types of form access
methods.

Richard.
From: Garrett Smith on
Richard Cornford wrote:
> On Apr 9, 5:38 am, Garrett Smith wrote:
> <snip>
>>> http://jibbering.com/faq/notes/square-brackets/

[...]
>
>> That is nonstandard
>
> Except in the sense that it has never been possible to show an HTML
> DOM environment where they don't work. But being standard or not is
> not relevant to which (recognizable) forms of bracket notation
> accessors would be equivalent (to showing the relationship between the
> strings in the brackets and the Identifiers following the dots).
>
It is not part of any official standard.

The consequence of using the shortcut `myForm.controlName` is a leaked
form control.

If the element named `controlName` gets a new name or id, or is removed
from the document, `myForm.controlName` still points to that element.

http://jibbering.com/faq/names/form_dom_removal.html


> Proposing this change is as silly as the previous suggestion that
> pointing out the equivalence between - document.body -,
> document['body'] - and - doucment['bo'+'dy'] - was wrong because
> nobody would ever use the latter two. Understanding how things work is
> not dependent on how they would be used.
>

I got that understanding the concept is the point of the article and the
example. My gripe is that the example uses nonstandard approach. That
approach has a nasty side effect and can be avoided by simply using the
standard approach.

The standard approach can be used as example without any harmful
consequence.

>> and can result in a leaked form control. HTML 5
>> terms this as some sort of feature.
>>
>> How about:
>> | var stringOfValue = document.forms.formName.elements.inpName.value;
>
> The next line of text reads; "This dot notation has three dots, so
> there are three points at which the square bracket notation could be
> used in place of the dot notation (these are all equivalent)". You
> want to have five dots, and so must add the additional equivalents to
> the following text, making it considerably more complex without adding
> anything to the explanation that is being provided (indeed, probably
> making it less clear).
>

The example could be made to fit that text.

| Various forms of dot notation property accessor can be used to
| reference the form named "formName":
| var form = document.forms.formName;

A novice who did not know how to get a form control now knows how to get
a FORM. If he keeps reading he will see the standard way to get that.

>> ?
>>
>> Although standard form control access is not the point of the
>> article,
>
> And examples of actual form access (rather than examples only of dot/
> bracket-notation property accessors) use the standard form access
> methods.
>
>> the examples should not propose the reader to use non-standard
>> access.
>
> It doesn't. Indeed pointing out that the simple 'shortcut' form exists
> and then not using it in the form access examples could be seen as
> discouraging its use (as the observant reader may recognize that not
> using the 'shortcut' accessors to work with forms would have been a
> deliberate decision).
>

That assumes that the reader reads both articles. I think that is too
much to expect. Some readers will scan/read enough to do what they want
to know and stop reading and continue on with whatever it was that set
them to find the answer in the first place.

>> Considering this is linked from an entry on how to access a named
>> form control, it has the effect of advocating non-standard code.
>
> There is a perfectly good article in the notes talking about form
> access that states the relative status of the types of form access
> methods.
>
http://jibbering.com/faq/notes/form-access/
That is linked from #formControlAccess entry.

--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Garrett Smith on
Garrett Smith wrote:
> Richard Cornford wrote:
>> On Apr 9, 5:38 am, Garrett Smith wrote:
>> <snip>
>>>> http://jibbering.com/faq/notes/square-brackets/

[...]

Regarding changing the FAQ note to use a DOM-compliant example (as
expressed below "proposed change"), how strongly do you feel about
keeping this.

Does else have an opinion on the proposed change?

> The standard approach can be used as example without any harmful
> consequence.
>
>>> and can result in a leaked form control. HTML 5
>>> terms this as some sort of feature.
>>>
>>> How about:
>>> | var stringOfValue = document.forms.formName.elements.inpName.value;
>>
>> The next line of text reads; "This dot notation has three dots, so
>> there are three points at which the square bracket notation could be
>> used in place of the dot notation (these are all equivalent)". You
>> want to have five dots, and so must add the additional equivalents to
>> the following text, making it considerably more complex without adding
>> anything to the explanation that is being provided (indeed, probably
>> making it less clear).
>>
>

Proposed change:
> The example could be made to fit that text.
>
> | Various forms of dot notation property accessor can be used to
> | reference the form named "formName":
> | var form = document.forms.formName;
>
> A novice who did not know how to get a form control now knows how to get
> a FORM. If he keeps reading he will see the standard way to get that.
>

[...]

--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Richard Cornford on
On Apr 9, 7:00 pm, Garrett Smith wrote:
> Richard Cornford wrote:
>> On Apr 9, 5:38 am, Garrett Smith wrote:
>> <snip>
>>>>http://jibbering.com/faq/notes/square-brackets/
>
>[...]
>
>>> That is nonstandard
>
>> Except in the sense that it has never been possible to show an
>> HTML DOM environment where they don't work. But being standard
>> or not is not relevant to which (recognizable) forms of bracket
>> notation accessors would be equivalent (to showing the
>> relationship between the strings in the brackets and the
>> Identifiers following the dots).
>
> It is not part of any official standard.

Neither is having a - document - property of the global object that
refers to an object implementing the Document interface. How much FAQ
code is going to be rendered non-function when you get around to
removing all instances of that?

<snip>
> I got that understanding the concept is the point of the article
> and the example. My gripe is that the example uses nonstandard
> approach.

It doesn't 'use' anything, it just shows a dot-notation property
accessor that is likely to be easily understood by people reading the
article, especially in relation to the bracket notation alternative
formulations.

> That approach has a nasty side effect and can be avoided by
> simply using the standard approach.

The best you could say is that it _can_ have nasty side effects (How
often do people actually change the name or ID of a form control?),
but since actually using that formulation is not encouraged by the
article (and is effectively discouraged) that is not relevant.

> The standard approach can be used as example without any harmful
> consequence.

The example (which was original chosen, over possible alternatives
(including all 'standard formulations), for its combination of
relative complexity and recognisably for the expected audience) is
fine as it is.

>>> and can result in a leaked form control. HTML 5
>>> terms this as some sort of feature.
>
>>> How about:
>>>|var stringOfValue = document.forms.formName.elements.inpName.value;
>
>> The next line of text reads; "This dot notation has three dots, so
>> there are three points at which the square bracket notation could
>> be used in place of the dot notation (these are all equivalent)".
>> You want to have five dots, and so must add the additional
>> equivalents to the following text, making it considerably more
>> complex without adding anything to the explanation that is being
>> provided (indeed, probably making it less clear).
>
> The example could be made to fit that text.
<snip>

Or it could be left alone.

>>> Although standard form control access is not the point of the
>>> article,
>
>> And examples of actual form access (rather than examples only of
>> dot/bracket-notation property accessors) use the standard form
>> access methods.
>
>>> the examples should not propose the reader to use non-standard
>>> access.
>
>> It doesn't. Indeed pointing out that the simple 'shortcut' form
>> exists and then not using it in the form access examples could
>> be seen as discouraging its use (as the observant reader may
>> recognize that not using the 'shortcut' accessors to work with
>> forms would have been a deliberate decision).
>
> That assumes that the reader reads both articles.

Which "both articles"? Examples of combining numbers with strings in
the expressions in bracket nation property accessors, relating to
forms and using the standard formulations, appear later in the article
on bracket notation property accessors. Indeed, they were deliberately
used to contrast the simpler form shown earlier.

> I think that is too much to expect. Some readers will scan/read
> enough to do what they want to know and stop reading and continue
> on with whatever it was that set them to find the answer in the
> first place.

Probably, but then the article must have made the point about the
relationship between dot and bracket notation property accessors, and
the specific examples that may have been read up until the point where
they stop reading will not significantly influence the behaviour of
such an individual.

>>> Considering this is linked from an entry on how to access a
>>> named form control, it has the effect of advocating
>>> non-standard code.
>
>> There is a perfectly good article in the notes talking about
>> form access that states the relative status of the types of
>> form access methods.
>
> http://jibbering.com/faq/notes/form-access/
That is linked from #formControlAccess entry.

No:-

<URL: http://jibbering.com/faq/faq_notes/form_access.html >

The FAQ question on strangely named controls links to the last section
of the bracket-nation property accessor article (which is long after
the example you have decided to quibble about), so there is no reason
to expect people interested in learning how to access form controls to
be reading that article at all. They should be being directed to the
form access article.

The people interested in bracket-notation are not necessarily
interested in applying it to form access at all, and if they are then
they will see specific examples of doing so in the way that you
consider 'correct'.

Richard.