+ 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
6 ответов
+ 1
Maybe you can use that
https://code.sololearn.com/WEy7TdmkdafY/#js
+ 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>
+ 5
thank you for answer but is it possible to show many div on multiple select?
+ 4
Of course, play with that code and change it
+ 4
okay ! thanks
+ 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