Retrieve and Print selected value of a <select>

Asked

Viewed 43 times

0

I have 1 <select></select> with various options and wanted to use jquery to recover the value of the one I selected and print in the div test, someone can 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>

2 answers

1


you can use the event change 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>
<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>

  • Thanks :D already solved

1

Try this, I think it should already solve:

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

Follow the example: http://jsfiddle.net/ivanferrer/t9n72u84/

  • Thank you, solved ;D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.