Jump to content

Forms: Datalist


silverRainfall

Recommended Posts

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 by silverRainfall
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...