1

I'm trying to output into a div the option selection of a select box - I only need the text of the option not the value. My following code gets all the text from all the options in my select field. How do I adjust so I only get the text of the option selected?

$("#metreSelect").change(function() {
  $('#metre').text($(this).text());
});
Dan Lee
  • 684
  • 4
  • 12
  • 32
  • `$("#metreSelect").change(function() { $('#metre').text($('option:selected',this).text()); });` use this – guradio Jun 15 '16 at 13:54
  • 1
    Possible duplicate of [Get selected text from a drop-down list (select box) using jQuery](http://stackoverflow.com/questions/1643227/get-selected-text-from-a-drop-down-list-select-box-using-jquery) – JJJ Jun 15 '16 at 13:56

1 Answers1

1

$("#metreSelect").change(function() {
  $('#metre').text($('option:selected', this).text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id='metreSelect'>
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
</select>

<span id='metre'></span>
  1. Get the option selected text
guradio
  • 15,359
  • 3
  • 33
  • 52