On 09-Jun-08, at 7:51 PM, Mark J. Reed wrote:
If you have any control over the HTML (as opposed to running
_javascript_ locally on someone else's HTML), the most reliable way of
addressing individual elements is to give them unique ID attributes
and use the document.getElementById() method, e.g.
<form id="login_form" method="post" action=""https://my.site/log/me/in">https://my.site/log/me/in">
<input id="username1" name="username" type="text" />
<input id="password1" name="password" type="text" />
...
</form>
Then you can get at the Form object via the call (
document.getElementById('login_form') ), even if new forms are added
earlier in the page. You can get to the Input fields either via the
form ( document.getElementById('login_form').username ) or directly by
their own identifiers ( document.getElementById('username1') ).