How can I customize what the dropdown defaults to?

So if we don’t select any option, the first option will be selected by default?
If yes, then is there any way to stop it?

For eg: If in the excercise if we don’t select any option then by I think “sesame” will be selected by default. Is there any way we can set another option, say “select any one” as default which does not allow progression if we don’t select any one of the options prrovided.

Attributes are very useful to customize behavior, in this case you need to use selected attribute:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#Examples

5 Likes

Is it ok to create a “None” option if the user didn’t want any of the options from the drop down list.
E.g None

sure, just set the value attribute to an empty string

4 Likes

if I wanted to make more than one item on the drop down list clickable how would I do this or is there a more compacted way of doing this without using checkboxes

using <select> element:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select

you have a multiple attribute, which, well i suppose you can guess what it does :wink:

1 Like

I know I am 6 months from the last reply, but who knows who may stumble upon this question
I don’t believe that you have the option to not select something from the drop down, for the webpage to compile and run the code, each line be able to be ran. However, if you wish to customize a default option lets say if none of the items listed are of interest you can use the following <option selected="selected">: or <option selected>

<select id="choice" name="choice">
  <option selected="selected"> (you can leave this blank) </option>
  <option value="1"> 1 </option>
 <option value="2"> 2 </option>

but not choosing options 1 or 2, you just click on the blank dropdown box.

2 Likes

I know this question has been answered already. Just wanted to contribute what I learnt from my own trial and error.

There is a way to make a default.

I tried it out by creating an with an empty value attribute and added the text ‘selected’ afterwards, thus:

That is nice to know