How to make one selected item in <datalist> : I mean default choice

Hello Seniors,
I am new to HTML.

I am working on a project exercise in Codecademy:
https://www.codecademy.com/courses/learn-html/projects/form-a-story

I want to show one item selected by default.

Please see my code:

<label for="quote">Quote:</label>
      <input type="text" id="quote" name="quote" list="quote-choices" required>
      <datalist id="quote-choices">
        <option value="winner gets ice cream"></option>
        <option value="runner up gets chocolate"></option>
        <option value="second runner up get pizza"></option>
      </datalist><br>

Please let me know how can I make one of item selected by default.

Thanks in advance.
:pray:

  • Madan

I don’t think that’s possible using a datalist.
You could use the value attribute for the input element.

(The selected attribute for options elements works when the options are children of a select element, but not for a datalist.)

1 Like

Thank you for you kind help. :pray: