View Full Version : quick question about form elements with "name" and "id" attributes.

04-03-2003, 10:13 PM
what is the difference between using the "name" attribute as opposed to using the "id" attribute in form elements? are there advantages to using one over the other?

04-03-2003, 10:36 PM
unless you specifically need something to have an 'id', you should always use 'name' for form elements. Non-named elements don't submit with the form.

04-04-2003, 07:57 PM
Also, form elements not marked with name attributes can't be accessed with DOM0 references (document.forms).

I would normally discourage anyone from using DOM0, but forms are core accessibility features; you can't let them break like you can with DHTML.

So use NAME for form elements, but not for anything else.

04-04-2003, 08:04 PM
If you want to reach a single form element through scripting, you use id. If you want to name an element or a group of elements something that you can use in the document.forms array or submit information, you should use name. You can use both and they don't have to be equal.

Name on img or a tags did have the same meaning as id though - so on them you should always use id. Only on form elements does name have additional/different functionality from id.

As for DOM0 and the DOM, it's not really the right question - name has an entirely different purpose from id.

04-04-2003, 08:16 PM
Originally posted by liorean
... stuff ...
Didn't we just have this conversation? ;)

04-04-2003, 08:27 PM
where? i'd be happy to read that discussion.

04-04-2003, 08:37 PM
It was on the evolt.org mailing list; http://lists.evolt.org/archive/Week-of-Mon-20030331/subject.html - the thread called "setting the value of a file input "

It didn't conclude much differently from this, I simply remarked because liorean and I both posted to it.

04-04-2003, 09:39 PM
Now I know why I had that Deja Vu feeling - I HAD done it before ;-)