Navigation: form and elements**
Shorter notation: form.name
There’s a shorter notation: we can access the element as form[index/name].
In other words, instead of form.elements.login we can write form.login.
That also works, but there’s a minor issue: if we access an element, and then change its name, then it is still available under the old name (as well as under the new one).
That’s easy to see in an example:
<form id="form"><input name="login"></form><script>alert(form.elements.login == form.login); // true, the same <input>form.login.name = "username"; // change the name of the input// form.elements updated the name:alert(form.elements.login); // undefinedalert(form.elements.username); // input// form allows both names: the new one and the old onealert(form.username == form.login); // true</script>
Backreference: element.form
For any element, the form is available as element.form. So a form references all elements, and elements reference the form.
Here’s the picture:
