can I use the same Id that I set for Name in HTML?

1

In order to manipulate the html tags in php I need to set a name for them, while javascript uses the id, but can I have some kind of future problem if I use the same name that I set for name in ids? br> Ex. <input type="text" id="user" name="user">
if not, is this practice recommended or used? Or by convention do you generally assign different names?

    
asked by anonymous 30.09.2016 / 04:44

1 answer

3

Yes, you can use the same value for the id and name attribute on the same element with no problems.

Note that the value of id must be unique for each document, since the value of name can occur more than once per document.

  

[...] while javascript uses id [...]

Just a note: You can select, by javascript, elements by id ( getElementById ) or by name ( getElementsByName ):

 console.log("Elemento por ID:", document.getElementById("user"));
 console.log("Elemento por Name:", document.getElementsByName("user")[0]);
  <input type="text" id="user" name="user">
    
30.09.2016 / 05:06