<input name="" id=""?

I have pages where I’ve got <input name=“blah” id=“blah” … where the name and id are the same.

Is it correct to have both name and id for an input element? Since I’m doing getElementById, would the id= be sufficient for all occurrences?

It doesn’t matter if they are the same or not, but you normally need them both. The name attribute identifies the input for the form processing script, which the id associates the input with an accompanying <label> element, which has a “for=” attribute.

E.g.

<label [COLOR="#FF8C00"]for="blah"[/COLOR]>Blah</label>
<input name="blah" [COLOR="#FF8C00"]id="blah"[/COLOR]>

The for=“blah” / id=“blah” associates the label with the input. That’s handy for people using a screen reader (who can’t “see” the relationships) and also means you can click on the Label to activate the input.

Of course, the id on the input can also be used as a hook for JS and CSS.

If you are going to use the same value for botha name and an id then you need to make sure they are on the same element. If one is on one tag and the other is on a different tag then Internet Explorer will become more confused than it normally is.

Is that just on older versions, or are the latest ones as dopey?

Good to know. I’m adding the id= to existing name= on form elements, and they do match each other only, and not other elements.