MilConDoin
MilConDoin

Reputation: 745

In HTML: Different <select> referencing the same list of options

Is it possible for <select>-lists to reference the same list of options, similar to <input> with <datalist>?

I generate a list of several entries, where (among other things) the user selects a value of a dropdownlist. The options in this list are the same for each entry, so I would prefer it, if the list of options doesn't need to be re-added for each dropdownlist.

I can't use <input> with <datalist>, since the user may only choose from available entries.

Upvotes: 1

Views: 487

Answers (2)

johannes janssens
johannes janssens

Reputation: 1

This is not realy the good answer. There is a big difference between 'datalist' and 'select' which for as far as I read till yet stays unspoken : in a select the 'value' can be different from the visualized 'innerHTML', which is not the case in a datalist. So what we need is a kind of 'select' with an attribute like 'selectlist="countries' the selectlist then would look like this :

<selectlist>
  <option value='1'>Belgium</option>
  <option value='2'>France</option>
</selectlist>

and can be reused in more then one 'select' and send the value back to the server instead of the innerHTML.

Upvotes: 0

Meku
Meku

Reputation: 107

you could do this using jquery easily,

<datalist id="mylist">
   <option value="a">
   <option value="b">
   <option value="b">
</datalist>

<select class="someSelect">
<select class="someSelect">

$(".someSelect").html( $("#mylist").html() );

this would replace all your select list from the datalist

Upvotes: 3

Related Questions