1
How to send the value of one of the options of a "select" to an input text?
1
How to send the value of one of the options of a "select" to an input text?
2
Given such an HTML:
<select id="meuSelect">
<option value="a">Alfa</option>
<option value="b">Beta</option>
<option value="g">Gama</option>
</select>
<input type="text" />
you can save objects to a variable like this:
var select = document.getElementById('meuSelect');
var input = document.querySelector('input');
then attach an event headphone to the select
. You must listen to the event change
and in the callback select
will be the this
. The rest is simple:
select.addEventListener('change', function() {
input.value = this.value;
// se quiseres o texto usa
// var option = this.children[this.selectedIndex];
// input.value = option.innerHTML;
});
perfect thank you very much. For good connoisseur a drop is letter.
@Magichat great. If you want you can mark the question as accepted. And the same in the other question - you can mark as accepted one of the answers.
You mean click on the icon that looks like a teacher’s visa? Regarding the option to take the text inside the element, your solution brings all the options and tags too, how to get only the text of one of the options selected? What other question does it refer to?
@Magichat Sorry, had a bug. Fixed :)
Perfect, like Magik ;) Point for you!
Browser other questions tagged php javascript
You are not signed in. Login or sign up in order to post.
your question this too vague I will vote for closing
– user45474
Could you provide more information to the question? I’m not getting to understand what you want.
– gato
@Gagel Gagel is new to the forum, in his opinion as would be the least vague way to ask what I asked?
– MagicHat
@Gagel Gagel *perguntar
– MagicHat