Difference between ID and Name in HTML

Name is coming from the initial DOM 0 (DOM Zero Level) interface
model. In this model form controls are identified by name or by index
in elements collection:
document.forms[0].elements[0];
document.forms[0].elements[“FirstControl”];
Only controls having name attribute set are being submitted, this rule
is in effect since then and forever.

id attribute was introduced only in DOM 1. As other poster pointed out
ID supposed to be unique for the given document, while name can be the
same for many elements (think of radio buttons group for instance).

This is why say accesskey is attached to ID and not to name. That is
not the only neither the main reason but it gives the idea why
sometimes it is useful to set both id and name for a form control,
like:

<input type=”radio” value=”yes” name=”rdg” id=”rd01″>
<label for=”rd01″>Yes</label>

<input type=”radio” value=”no” name=”rdg” id=”rd02″>
<label for=”rd02″>No</label>

For anchors and links collections name attribute usage is deprecated
and rarely used.

document.images[“ImageName”] is still pretty much in use.

Original Document

Don't be shellfish...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on TumblrEmail this to someone

Leave a Reply