I read somewhere that most form elements should have an id and name attribute, but now I forget the reasoning and part of me does not agree. Is that how you markup your forms?
| SitePoint Sponsor |
I read somewhere that most form elements should have an id and name attribute, but now I forget the reasoning and part of me does not agree. Is that how you markup your forms?
For most form controls, the name attribute is required. When a form is submitted, it is the name+value that is sent to the server. If you use id instead of name, you are not guaranteed the data will be sent, or if it is, with the proper key.
"name" and "id" share a namespace, so if a name token is used one place, an id with the same token may not be used elsewhere.
CSS does not address the name attribute, so the id must be used if you want to style a given element. Also, the for attribute expects the id of the referenced element. Thus id and name, with the same token on an element is quite common.
cheers,
gary
Anyone can build a usable website. It takes a graphic
designer to make it slow, confusing, and painful to use.
Simple minded html & css demos and tutorials
I like using the id attribute for DOM scripting and find name/value pairs useful for submitting variables to server side scripts.


A form control usually needs a name attributes, because only such controls are sent in the submit request.
Text fields, password fields, checkboxes, radio buttons, file selectors, select lists and textareas normally need an id attribute as well, so that the corresponding label element can be associated with it (via its for attribute).
Hidden fields and push buttons don't have labels and don't need an id attribute unless you want to access them with JavaScript.
Birnam wood is come to Dunsinane


Anyone can build a usable website. It takes a graphic
designer to make it slow, confusing, and painful to use.
Simple minded html & css demos and tutorials


Bookmarks