Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the point of HTML forms `name` attribute?

Tags:

html

forms

What's the point of the name attribute on an HTML form? As far as I can tell, you can't read the form name on submission or do anything else with it. Does it serve a purpose?

like image 574
Yarin Avatar asked Jan 20 '12 18:01

Yarin


People also ask

Why does a form element need a name?

The HTML <form> name Attribute is used to specify the name of a form Element. It is used to reference the form-data after submitting the form or to reference the element in a JavaScript.

Is name attribute required?

The name attribute is probably the most important attribute of the <input> element. It isn't strictly required for validation, but you should never omit it. When a form is submitted to the server, the data from the form is included in an HTTP request. The data is packaged as a series of name-value pairs.

What is the point of form tag HTML?

The <form> element also allows you to define method and action attributes, which tell the browser what to do when the form is submitted.


1 Answers

In short, and probably oversimplifying a bit: It is used instead of id for browsers that don't understand document.getElementById.

These days it serves no real purpose. It is a legacy from the early days of the browser wars before the use of name to describe how to send control values when a form is submitted and id to identify an element within the page was settled.

like image 106
Quentin Avatar answered Sep 20 '22 12:09

Quentin