2
Given the code:
var select = document.getElementById('meuSelect');
var input = document.querySelector('input');
select.addEventListener('change', function() {
var option = this.children[this.selectedIndex];
input.value = option.innerHTML;
});
<select id="meuSelect">
<option value="a">Alfa</option>
<option value="b">Beta</option>
<option value="g">Gama</option>
</select>
<input type="text" />
(provided by @Sergio reference)
The code performs the function with a select, the question is : How to get the same result, but with multiple select, where each selected option will be sent to the same input, forming for example a sentence, where each select is a word that composes the phrase? I’m sorry I wasn’t clear.
For example:
<select id="meuSelect1">
<option value="a">Alfa</option>
<option value="b">Beta</option>
<option value="g">Gama</option>
</select>
<select id="meuSelect2">
<option value="a">Delta</option>
<option value="b">Épsilon</option>
<option value="g">Digama</option>
</select>
<select id="meuSelect3">
<option value="a">Zeta</option>
<option value="b">Eta</option>
<option value="g">Teta</option>
</select>
<input type="text" />
How to proceed in javascript?
input.value += option.innerHTML;
?– user28595
Only with 3 selects?
– David
@David In the case will be more, but more than 1 as an example already serves me to adapt here...
– MagicHat