+ 4
What is the difference between id and name attribute in input tag?
<input id="mysearch" name="searchitem" type="search" /> Sometimes i saw codes that does'nt put one of them. Not sure either id or name attributes.
4 Respuestas
+ 9
input name attribute is meant for screen readers and form processing, that's HTML5 making the web accessible to all. The id is purposely meant to be targeted by css and JavaScript for styling and dynamic manipulations.
+ 6
Id value is expected to be unique for each element in a document context (<html>), while name is expected to be unique in a <form> for unique or collection of elements (grroup of radio button for example )...
https://developer.mozilla.org/en-US/docs/Web/API/Element/name
https://developer.mozilla.org/en-US/docs/Web/API/Element/id
+ 3
name attribute is used to process a form submition
id attribute is for identify the html element in css styling, or javascript processing
+ 2
Just want to add that the name attribute is also used in forms when submiting data to server.