Reputation: 55
Method 1, ex. 1:
<form>
<label for="name"> Name: </label>
<input type="text" id="name" />
</form>
Method 1, ex. 2:
<form>
<label for="name">First name:</label>
<input id="lfname" name="fname" type="text">
</form>
—> Both structures look the same in browser. Both inputs include input id and + input type (in different chronological order, I guess that does not matter when using attributes?) - but: why does the 2nd also include name= again, if it looks the same on the browser anyway?
Method 2, ex. 1:
<form>
<label>
Name:
<input type="text" />
</label>
</form>
Method 2, ex. 2:
<form>
<label>Name
<input id="User" name="Name" type="text" />
</label>
</form>
—> Both structures look the same in browser. Here: In the 2nd, input id and name is used & in the 1st example both are left out and only type specified. How come?
Upvotes: 0
Views: 244
Reputation: 118
The attribute name
is used for many purposes in PHP it is used to get the data of the input tag and many more.
The attribute id
is also used for many purposes like in javascript you get the by using document.getElementById
and many more
Upvotes: 1
Reputation: 70
name in an input element is used for backend purposes and ID too but in most cases you as a frontend dev will find yourself using it in CSS and JAVASCRIPT as well.
Upvotes: 1