-1

I need to get the text and not the value but I don't know how.

Sample code:

<select id="a2">
  <option value="b1">Burger Mcdo(Php 30.00)</option>
  <option value="b2">Cheeseburger (Php 39.00)</option>
  <option value="b3">Crispy Chicken Sandwich (Php 39.00)</option>
  <option value="b4">Double Cheeseburger (Php 80.00)</option>
  <option value="b5">Big Mac (Php 100.00)</option>
</select>

I can get the option value w/:

var z2 = document.getElementById('a2').value;

But I want to get the text value (ex.Big Mac (Php 100.00))

  • 3
    Possible duplicate of [Get selected value in dropdown list using JavaScript?](http://stackoverflow.com/questions/1085801/get-selected-value-in-dropdown-list-using-javascript) – Ozan Nov 21 '15 at 10:04

1 Answers1

1
  //get the select    
  var select = document.getElementById('a2');

   console.log(select);

  //set onchange handler
     select.onchange= function(e){
   //get selected index
     var idx = select.selectedIndex;

    //get content of selected option 
      var option = select.options[idx].textContent;
     console.log(option);
 };
Ramanlfc
  • 8,283
  • 1
  • 18
  • 24