Bart said:
Randy Webb wrote:
Definitely - When it comes to technical accuracy, you can trust
(some groups on) usenet (on some type of questions): I mean, if
someone's wrong, somebody else will correct him
That so-called
"battle test" is the best guarantee for software quality.
<snip>
That is pretty much an invitation to have someone quibble about your
code ;-)
So here goes:-
| <form name="myForm">
In valid HTML a FORM attribute is required to have an ACTION attribute.
Because of the issues arising directly from attempting to script the
DOMs created from structurally invalid mark-up it is proposed that
mark-up examples, even fragments, should be valid. That is probably
going too far as no evidence has yet been presented that invalid and
missing attributes contribute to scripting issues.
| <select name="F1" size="1"
In a SELECT element that is not MULTIPLE does a - sive="1" - attribute
do anything worthwhile?
| onChange="document.myForm.F2.value=this.value">
You have elected to use the non-(W3C HTML DOM) standard 'shortcut'
property accessors of accessing the FORM element as a property of the
document and the form control as a property of the FORM element.
The W3C HTML DOM standard, and fully back-compatible alternative:-
document.forms['myForm'].element['F1'].value
(or dot notation equivalent) is preferred because it is:-
1. Self documenting, in that looking at the property accessor makes it
obvious that the - document.forms['myForm'] - is a reference to a
form, and that - .element['F1'] - is a reference to an element
(control) within that form. While - document.myForm - may be
confused with references to IMG, EMBED and some other elements that
may also be made available as 'shortcut' named properties of a
document (the name not withstanding as the name of a form in a
non-example should probably say something about the role of the
form), and - .F1 - may be confused with a reference to a property
of the FORM element (some host provided property or an expando).
2. Supported in a wider range of DOMs (as there are good reasons not
to expect XHTML DOMs to support any 'shortcut' property accessors).
However, all form controls have a - form - property that refers to the
form that contains them (or is null if they are not contained in a form)
so the left hand side of the assignment could be shortened to:-
this.form.element['F1'].value
Which makes the form access anonymous (so more flexible/portable).
Although the W3C HTML DOM does specify that the currently selected
OPTION's value be reproduced as a - value - property of the SELECT
element using this sacrifices some back-compatibility with Netscape 4
and some of its contemporaries. The Equally standard:-
this.options[this.selectedIndex].value
- reliably retrieves the value of the selected OPTION in all browsers
known to expose SELECT elements for scripting.
Leaving the assignment as:-
this.form.element['F1'].value = this.options[this.selectedIndex].value;
Richard.