"Bruce Duncan" <bruce~w~duncan@~hotmail.com> writes:
[color=blue]
> The reason I ask is because I was just thinking about the following...which
> is better and/or why?
>
> document.forms["myform"].elements["txtname"].value
> or
> document.myform.txtname.value[/color]
The former is better for one, very important, reason: It is correct
according to the W3C DOM.
The latter assumes that the form element object is a property of the
document object, with the same name as the form.
For all current browsers, that is almost always the case (one
exception is Gecko browsers in standards mode and where the form has
only an id-attribute and no name-attribute - then the form is still
part of the forms collection, but not a property of the document
object).
However, there is no guarantee that future browsers will all honor
this tradition of polluting the document object (I hope they won't,
it's really annoying - try making a form with id="body"!)
The former is both correct according to standards, meaning it will
almost certainly work in all future browsers, *and* will work in all
Javascript enabled browsers since Netscape 3 (Netscape 2 didn't allow
access by name, only by number).
/L
--
Lasse Reichstein Nielsen -
Join Bytes!
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'