The Form “ID” Attribute Versus The “Name” Attribute

January 9, 2010

Up until now, in a situation where you have several forms in one page, Web-form-buddy has asked you to use the “name” attribute of the form tag in order to distinguish one form from another. Like this:

<form name="xyz" method="post" action="your-script-name.cgi">

Well  this will still continue to work with your existing forms. But we have decided from now on to move over to using the form “id” attribute instead. Like this:

<form id="xyz" method="post" action="your-script-name.cgi">

There are two reasons for this:

1) In XHTML the “name” attribute is not supported. In particular we have discovered that the popular web editing tool Wordpress (with which I am writing this!)  makes it hard to use the “name” attribute with a form tag.

2) A nice feature of the ID attribute is that it is designed to provide a unique identity for an HTML element. A really good web authoring tool should make it impossible to create two HTML elements with the same ID attribute. The uniqueness of the ID attribute is why it is used in Javascript to access HTML entities. And that characteristic, of forcing a unique ID,  is exactly what Web-form-buddy is looking for when you have more than one form in a web page.

So we think it suits our purposes just nicely!

Leave a Comment

Previous post:

Next post: