Tell us what’s happening:
I have a problem in understanding what’s wrong with my code, because I keep getting error on “You should have a select field with an id of dropdown .”
That’s my piece of code that contains select field:
<fieldset>
<label id="dropdown" name="dropdown">Which option best describes your current role?
<select name="dropdown" id="dropdown" required>
<option value="">Select current role</option>
<option value="1">Student</option>
<option value="2">Full time job</option>
<option value="3">Full time learner</option>
<option value="4">Prefer not to say</option>
<option value="5">Other</option>
</select>
</label>
</fieldset>
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 OPR/102.0.0.0
As @aroobanoor has explained the label should have the for attribute, not the id attribute. Change the id in the label to for instead and see if that works for you.
Please if it does work, credit @aroobanoor with the solution as it was provided by them.
Technically, ids are supposed to be unique on the page, which means that two elements cannot have the same value for their id attribute. So anytime you find yourself duplicating ids in your HTML you need to change one of them to something else. In this case, the id of dropdown is required to be on the select so if you need an id on its label then you’ll need to pick a new value.
Yes, you need to add for=“dropdown” in the label element. Also, as @bbsmooth mentioned, you cannot have 2 elements with the same. But you don’t need an id for the label element. You should remove it.