+ 3

How to show many selected option with value

Hi i would like to know how to show a selected option in a DIV with script

28th Oct 2017, 8:46 AM
Ababacar Thiendella FALL
Ababacar Thiendella FALL - avatar
6 ответов
28th Oct 2017, 9:20 AM
Daniel
Daniel - avatar
+ 6
<select id="mySelect" oninput="change()"> <option>item</option> <option>item 1</option> <option>item 2</option> <option>item 3</option> <!-- ... --> </select> <div id="myOutput"></div> <script> function change() { var select = document.getElementById("mySelect"); var output = document.getElementById("myOutput"); var index = select.selectedIndex; var value = select.options[index].value; output.textContent = value; } /* // ... or onlined: document.getElementById( "myOutput" ).textContent = document.getElementById("mySelect").options[document.getElementById( "mySelect" ).selectedIndex].value; </script>
28th Oct 2017, 9:27 AM
visph
visph - avatar
+ 5
thank you for answer but is it possible to show many div on multiple select?
28th Oct 2017, 9:25 AM
Ababacar Thiendella FALL
Ababacar Thiendella FALL - avatar
+ 4
Of course, play with that code and change it
28th Oct 2017, 10:05 AM
Daniel
Daniel - avatar
+ 4
okay ! thanks
28th Oct 2017, 10:05 AM
Ababacar Thiendella FALL
Ababacar Thiendella FALL - avatar
+ 4
<select><option> paired elements doesn't allow multiple selection... to be able to do multiple select, you need to implement your own (possibily with 'checkbox' <input> type), or use the <select><option> paired elements as switch rather than as selector: I can write you a basic example, but: 1> you doesn't react to my previous answer, so I ask myself if I have correctly understood your question or even if you don't care of my effort to make advanced code self explaining rather than just post a code example without explanation 2> there are at least two ways to interpret your question and so what you are waiting for: + showing the value(s) of selected(s) items in once div + showing/hidding particulars html elements (could be <div> or anything else) if related option is selected
29th Oct 2017, 5:01 AM
visph
visph - avatar