So that's the datalist element. It makes sense.
But we haven't really spoken about the autocomplete attribute.
What is that all about?
Well, at its core, the autocomplete attribute can be used to tell the browser to, you guessed it,
autocomplete
the user's data. And this autocomplete attribute is provided to us by HTML.
It's part of the HyperText Markup Language. And it's available not on every single element.
It's available on input elements, textarea elements, select elements and form elements.
And when its value is set to on, it just means the browser can use the values for future use and suggest
values
now.
So how does it look?
Well, here's an example of us using an input element where we put the autocomplete attribute to the
on state.
"Well, Clyde, okay, it's all good and well that it's on, but who comes up with the values?"
Like I mentioned, right,
it's part of the HyperText Markup Language and it's basically up to the browser as to what values are shown
to a user.
Typically, values come from past values entered into by a user, but they may also come from pre-configured
values from the browser.
For example, the browser might even let the user save their name, address, phone number, email address
for autocomplete purposes.
I guess what I'm trying to say is you can view datalist as being kind-of under your control, and the
autocomplete as being under the browser's control.
Your head might be spinning ðŸ˜µ.
You might be thinking, "Well, what is the difference between autocomplete and datalist?"
Well, that is a very, very good question.
Autocomplete tells the browser to give a user options for completion.
Okay, so it's kind of up to the browser.
You kind of giving control over to the browser.
And bear in mind, even if we set autocomplete to off, especially when it comes to passwords, browsers
still implement their own password management system and they still might ask the user, do you want
to save the password for future use?
That's not up to you and I.
It's up to the browser. And you can kind of view autocomplete as something similar.
We're giving the browser control to show the user certain values.
Then we've got datalist.
And datalist is really cool because we're in control as to what list suggestions we want to be displayed
to the user.
And of course it's regardless of previous input. Wow, I know we've gone through quite a lot, but I hope
this has made sense and I hope you're getting more intuitive now and feeling more comfortable about
how to use the autocomplete box.