silverRainfall Posted November 22, 2023 Share Posted November 22, 2023 (edited) Hello everyone, I hope I may ask for your wisdom. I'm doing the W3 certified course for HTML. I have a question about module 7.3, discussing form elements. My question is about the datalist-element, also publicly explained here: https://www.w3schools.com/tags/tag_datalist.asp W3's brevity in terms of explanation can be highly appreciated (if you have some preceding knowledge), but in this instance it disallowed me to understand the HTML I saw presented for the datalist-element: <label for="browser">Choose your browser from the list:</label> <input list="browsers" name="browser" id="browser"> <datalist id="browsers"> <option value="Edge"> <option value="Firefox"> <option value="Chrome"> <option value="Opera"> <option value="Safari"> </datalist> First of all, it seems to me that the input attribute list should correspond to the id attribute of datalist, like the for attribute for label would refer to the id of an input element. Is my understanding correct? My greatest question however is, is that that the input element is not being declared an input type (there is no type attribute) and yet the input element, when the HTML is opened in a browser, shows as if the input type is set to text. Does this mean that whenever we apply the list attribute to the input element, it automatically renders as a text field? Thank you for your clarification! silverRainfall Edited November 22, 2023 by silverRainfall Link to comment Share on other sites More sharing options...
Ingolme Posted November 22, 2023 Share Posted November 22, 2023 There is some information available in the reference. Here's the description of the list attribute which specifies that it expects the id of a <datalist> element: https://www.w3schools.com/tags/att_input_list.asp <input> elements without a type attribute are always assumed to be text inputs by browsers. It's mentioned in the reference page as well: https://www.w3schools.com/tags/att_input_type.asp 1 Link to comment Share on other sites More sharing options...
silverRainfall Posted November 24, 2023 Author Share Posted November 24, 2023 On 11/23/2023 at 12:03 AM, Ingolme said: There is some information available in the reference. Here's the description of the list attribute which specifies that it expects the id of a <datalist> element: https://www.w3schools.com/tags/att_input_list.asp <input> elements without a type attribute are always assumed to be text inputs by browsers. It's mentioned in the reference page as well: https://www.w3schools.com/tags/att_input_type.asp Thank you Ingolme; I'm happy I have understood it correctly. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now