[thelist] javascript and IDs

Christian Heilmann codepo8 at gmail.com
Tue Oct 4 11:44:33 CDT 2005

> Ok, so I have a <form id="foo">
> Is this the best way to access descendents of <form>?
> By keying off the ancestor, and then looping through
> it's elements?
> Or should I give each form element it's own id...

As the label of the form corresponds with the ID and you should use
labels for accessibility, it is not a bad idea.

> I want to change the value of an attribute of an input
> field:
> <input type="text" name="foo">
> want to change it to
> <input type="text" name="bar">

> What I ended up doing was giving the <input> element
> an id="searchfield", and then looping through it's
> attributes using '.attributes' on the input object,
> and testing the name of the attribute == 'name'. and
> then replacing it's value with 'bar'.

Why not document.getElementByID('searchfield').name='bar'; ?
Why do you want to change the name of a field on the fly anyway?

Chris Heilmann
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/
Binaries: http://www.onlinetools.org/

More information about the thelist mailing list