by joshuahedlund · 14y ago · 0 comments
> GOOD: document.forms["formname"].elements["inputname"]
> BAD: document.formname.inputname
Square bracket notation is awesome for mixing in variables - it saves you from using the evil eval() - and obviously BAD is worse than GOOD, but if you have no variables what about this:
> ?: document.forms.formname.inputname
If there's no functional difference it's shorter and simpler than GOOD
I use the elements collection because the behaviour of adding each input as a property to the parent form element is a mistake.
I use the bracket notation because it highlights the difference between the implementation symbols and the actual data which is being manipulated. What I mean is that I see a property specified with the dot notation on the same level as an identifier and as such its name is just to remind us humans of its purpose, whereas a property accessed using bracket notation is important both to us and to the program since it specifies a data point.
I personally find it more useful to deal with forms using some kind of abstraction on top so I doubt I'd use either variations in anything other than a very simple page.