Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML 5 difference input id and input name? [duplicate]

Tags:

html

input

I'm busy with something for school in HTML 5.

So here is my bit of code

<label for="name">Name</label>
<input type="text" id="name" name="name" placeholder="your name" required><br>

So my question actually is:

What is the difference between the NAME and the ID? purpose? which one is more important?

like image 796
Nick Zijlstra Avatar asked Apr 15 '12 20:04

Nick Zijlstra


People also ask

Is input name same as id?

Of course, you can use the same denomination for your id and name attribute. These two will not interfere with each other. Also, name can be used for more items, like when you are using radio buttons.

What is the difference between id and name attribute in HTML?

id is used to identify the HTML element through the Document Object Model (via JavaScript or styled with CSS). id is expected to be unique within the page. name corresponds to the form element and identifies what is posted back to the server.

Can name be same as id HTML?

Yup! This is absolutely fine. name is used during form submission to POST/GET the values.

Should input names be unique?

ID should be unique but you can use multiple form elements with the same NAME. This is standard for how radio buttons work so you can force one seletion of a radio button group.


2 Answers

In short, the name is the identifier that is sent to the server when you submit the form. The id is a unique identifier for the browser, clientside, for javascript and such.

like image 183
Joe Frambach Avatar answered Oct 23 '22 16:10

Joe Frambach


The name attribute is for submitting a form element to the server; many elements may share the same name (e.g. radio buttons, which must have the same name within the set).

The id attribute is for uniquely identifying any element (not just form elements). It must be unique throughout the entire document.

like image 36
Phrogz Avatar answered Oct 23 '22 16:10

Phrogz