Retrieve and Print selected value from a select

0

I have 1 <select></select> with several options and I wanted to use jquery to recover the value of the one I had selected and printed on the test div, can anyone help me?

<select id="resultado_team2_CSGO">            
    <option value="Fnatic">Fnatic</option>
    <option value="tenvyus">Team EnVyUs</option>
    <option value="tsm">Team Solomid.</option>
    <option value="nip">Ninjas in Pyjamas</option>
    <option value="navi">Na'Vi</option>
 </select> 
<div class="teste"></div>
    
asked by anonymous 04.09.2015 / 19:36

2 answers

1

You can use the change event for this.

var resultado = $("#resultado_team2_CSGO");
var teste = $(".teste");

resultado.on("change", function (event) {
  teste.html(event.target.value);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><selectid="resultado_team2_CSGO">            
    <option value="Fnatic">Fnatic</option>
    <option value="tenvyus">Team EnVyUs</option>
    <option value="tsm">Team Solomid.</option>
    <option value="nip">Ninjas in Pyjamas</option>
    <option value="navi">Na'Vi</option>
 </select> 
<div class="teste"></div>
    
04.09.2015 / 19:41
1

Try this, I think you should solve it:

$(function(){
    $('#resultado_team2_CSGO').on('change', function (e) {
        var optionSelected = $("option:selected", this);
        var valueSelected = this.value;
        $('.teste').text(valueSelected);
    });
  });

Follow the example: link

    
04.09.2015 / 19:46