HTML Tutorials

Setting the name of the form

The name attribute lets you set a unique identifier for a form so that you can distinguish between forms when working with the Document Object Model (DOM). The name attribute is distinct from the id global attribute, and in most cases, HTML documents use the id attribute for CSS selectors. Below we can see a form element to which the name and id attributes have been applied. We have used the same value for both attributes for the sake of simplicity.

    <meta name="author" content="Adam Freeman"/>
    <meta name="description" content="A simple example"/>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <form name="fruitvote" id="fruitvote" method="post" action="http://titan:8080/form">
      <input name="fave"/>
      <input name="name"/>
      <button>Submit Vote</button>

The value of the name attribute is not sent to the server when the form is posted, which is why this attribute has value only in the DOM and is not as important as the name attribute on the input element. If an input element doesn’t have a name attribute, the data that the user has entered will not be sent to the server when the form is submitted.