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?
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.
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.
Yup! This is absolutely fine. name is used during form submission to POST/GET the values.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With