Earlier I studied that for text
type input tag id
attribute and for
attribute of the label
tag should have the same value.
Now I was reading a tutorial and came through this code, here in the case of radio buttons
the for
and name
attribute have the same value, instead of id
and for
.
And I am aware that id
is unique for an element. My first question is then what is the purpose of using the for
attribute in the case of radio buttons?
<label for="status">Status:</label>
<input type="radio" id="pending" name="status"> Pending
<input type="radio" id="resolved" name="status"> Resolved
<input type="radio" id="rejected" name="status"> Rejected
My second question is that unlike the text
type input tag here id
and for
attribute do not have the same value. Is it a valid code? If it is valid then what is the purpose of giving the same values to the for
and name
attribute?