How do I select Multiple to allow you to select only one item?

Asked

Viewed 103 times

-7

I have a select:

<select multiple="multiple"> 
<option value="0">teste</option>
<option value="1">teste 1</option>
<option value="2">teste 2</option>
<option value="3">teste 3</option>
<option value="4">teste 4</option>
<option value="5">teste 5</option>
</select>

In this select I would like to be able to select only 1 item from the list, but I want to appear all items in list format, so the use of Multiple, how could solve this?

Note: I won’t be able to use the property size because the list size is dynamic, the list comes from the back-end.

1 answer

2

My colleague, you’re using the attribute multiple to be able to select multiple options from the drop-down list, this is the real purpose of the attribute multiple(select multiple elements). So you can make the elements <option> are all displayed you can use the attribute size with the defined value for 6 which is the amount of elements <option> in the element <select>, this is in order to be able to sample a certain number of elements visible in the drop-down list:

Example

<select size="6"> 
     <option value="0">teste</option>
     <option value="1">teste 1</option>
     <option value="2">teste 2</option>
     <option value="3">teste 3</option>
     <option value="4">teste 4</option>
     <option value="5">teste 5</option>
</select>

  • i gave an example when putting 6 items in select, I will not be able to use the size because the list size is dynamic, the list comes from the back end.

  • @Stand Alone, if that was also what you want, then you had to have put that in the question too.

  • Ok I’ll edit adding this thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.