-1
<select id="bethorse">
  <option value="horse1">White</option>
  <option value="horse2">Blue</option>
  <option value="horse3">Green</option>
  <option value="horse4">Brown</option>
</select>

S searched but the answers were for the selected text and I used this code bethorse= document.getElementById('bethorse').value;. It gives me number of the position the test. For example value 3 for horse4 just like in array.

Reporter
  • 3,897
  • 5
  • 33
  • 47
Shiva Khattri
  • 13
  • 1
  • 7

2 Answers2

0
var e = document.getElementById("bethorse");
var option = e.options[e.selectedIndex].value;

The variable option will hold the value of selected option.

deceze
  • 510,633
  • 85
  • 743
  • 889
Adrian
  • 8,271
  • 2
  • 26
  • 43
0

Your code is working in this example:

<select id="bethorse">
      <option value="horse1">White</option>
      <option value="horse2">Blue</option>
      <option value="horse3">Green</option>
      <option value="horse4">Brown</option>
    </select>

<button onclick="javascript:alert(document.getElementById('bethorse').value);">
    test
</button>
deceze
  • 510,633
  • 85
  • 743
  • 889
Stefan Koenen
  • 2,289
  • 2
  • 20
  • 32